Presentation title here

Building Microservices
with Service Fabric
Paolo Salvatori – Azure CAT
P R E S E N TA
Agenda
•
•
•
•
•
Microservices 101
Service Fabric intro for developers
Building Service Fabric apps
Service Fabric cluster
Resource balancing
 capacity properties
 placement properties
The trouble with monoliths…
The trouble with monoliths…
•
Tightly coupled components
 All components updated together
 Not agile, time to market suffers
The trouble with monoliths…
•
Tightly coupled components
•
Scale by cloning entire apps
 All components updated together
 Not agile, time to market suffers
 All components scaled similarly  expensive
The trouble with monoliths…
•
Tightly coupled components
•
Scale by cloning entire apps
 All components updated together
 Not agile, time to market suffers
 All components scaled similarly  expensive
What is a Service?
• Code solving a domain-specific problem
• Built by small team using a specific technology
stack
• Exposes features to caller via a well-defined API
contract
• Degrades gracefully when dependent services
fail
• Can be upgraded & scaled independently
of other services
• Dividing a big service into smaller services is
often referred to as a microservices architecture
Microservices…
• Myths
 microservices offer small, easy-tounderstand/manage code bases
 A monolith can use OOP & libraries (requires developer
discipline)
 Library changes cause build failures (not runtime failures)
 A failing service doesn’t impact other services
 Many services require dependencies be fully functioning
 Hard to write/test code that gracefully recovers when
dependency fails
 We run multiple service instances so there is no such thing
as “failure”
 A monolith is up/down completely; no recovery code
Microservices…
• Do one thing well
 Manage independent code and state
 Are generally developed by a small cross-functional team
 Are built with task-appropriate languages/frameworks
Microservices…
• Do one thing well
 Manage independent code and state
 Are generally developed by a small cross-functional team
 Are built with task-appropriate languages/frameworks
• Are loosely coupled




Communicate over well-defined interfaces/protocols
Have unique names (URI) that can be resolved
Are independently updated
Are independently scaled
Microservice Architecture Actual Benefits
Photo Share
Photo Share
Service
Photo Share
Service
Photo Share
Service
Service
Thumbnail
Thumbnail
Service
Thumbnail
Service
Service
Photo Share
Service
node.js
Thumbnail
Service
.NET
Photo Share Service
Photo Share
Service
V1
Thumbnail
Service
V1
V2
SharedLib-v1
Thumbnail
SharedLib-v7
Photo Share
Service
Thumbnail
Service
SharedLib-v1
SharedLib-v7
Monolithic application
App 1
• Scales by cloning
the app on multiple
machines
Microservices application
• Scales by deploying
each service
independently
• Better density: run
more apps on less
VMs
App 1
App 2
Monolithic application
Microservices application
• State: Single monolithic database
• Tiers of specific technologies
• Graph of interconnected services
• State typically scoped to the service
• Variety of technologies used
stateless
presentation
services
stateless
services
stateful
services
stateless services with
separate stores
Goodness…
• Increase agility through componentization
• Simplify upgrades through independent versioning
• Maximize productivity through heterogenous
technologies
• Improve hardware utilization through granular resource
balancing
• Limit the impact of failures through isolation
Turning a Monolith into a Microservice
IntelliSense, refactoring & compile-time type-safety)
•
Comparing an in-process call to an HTTP request
 Performance: Worse & increases network congestion
 Unpredictable time: Managing timeouts is challenging; pass deadlines
 Unreliable: Requires retry loops with exponential backup/circuit breakers
 Server code must be idempotent
 Security: Requires authentication, authorization, & encryption
 Debugging: network issues, perf counters/events/logs, causality/call stacks
However, devs now need to code for…
•
•
•
•
•
Service discovery
State management
Service lifecycle management
Health reporting
Resource governance
However, devs now need to code for…
•
•
•
•
•
Service discovery
State management
Service lifecycle management
Health reporting
Resource governance
Microsoft Azure Service Fabric
A platform for reliable, hyperscale, microservice-based applications
Microservices
High Availability
Simple
programming
models
Hybrid Operations
High Density
Hyper-Scale
Azure
Data Partitioning
Rolling Upgrades
Automated Rollback
Service Fabric
Low Latency
Stateful services
Health
Monitoring
Placement
Constraints
Private cloud
Container Orchestration
& lifecycle management
Fast startup &
shutdown
Self-healing
Replication & Failover
Resource balancing
Other clouds
Service Fabric Cluster
Node
Node
Node
Node
Node
Node
Service type / Named Service Instance
• Service Type
 Defines the service, like a class
• Composed of code/config/data packages
 Code packages define an entry point (dll or exe)
 Config packages define service specific config information
 Data packages define static resources (e.g. images)
• Packages can be independently versioned and upgraded
• Named Service Instance
<ServiceManifest Name="QueueService" Version="1.0">
<ServiceTypes>
<StatefulServiceType ServiceTypeName="QueueServiceType" HasPersistedState="true" />
</ServiceTypes>
<CodePackage Name="Code" Version="1.0">
<EntryPoint>
<ExeHost>
<Program>ServiceHost.exe</Program>
</ExeHost>
</EntryPoint>
</CodePackage>
<ConfigPackage Name="Config" Version="1.0" />
<DataPackage Name="Data" Version="1.0" />
</ServiceManifest>
Categories of services
• Guest executables and guest containers
 Deploy and manage arbitrary services written in any framework (.exe, Java,
Node, etc.) .
 Service Fabric makes these apps reliable as it guarantees that the specified
number of instances is always running
• Stateless Services
 State persisted to external storage, such as Azure DBs
 Existing web (ASP.NET) and worker role applications
• Stateful Services
 Reliability of state through replication and local persistence
 Lowers latency
 Reduces complexity in traditional three tier architectures as no additional
DBs, caches or queues are required
 Partitioned services allow to divide state (data) and compute into smaller
accessible units to improve scalability and performance.
Service Fabric Frameworks
Reliable Services
Reliable Actors
Application Type
• Declarative template for creating an application
• Based on a set of service types
• Used for packaging, deployment, and versioning
Applications and Services Yo, Service Fabric, I need
3 new Job Runner services!
MyApp Type 4.0.0
fabric:/app/job1
fabric:/app/job2
fabric:/app
fabric:/app/job3
Service
Fabric
Web Service Type
1.0.0
User Service Type
1.5.0
fabric:/app/job1
fabric:/app/users
fabric:/app/web
Job Runner Service Type
1.2.0
fabric:/app/job2
Authentication Service Type
3.1.4
Session Service Type
1.2.0
fabric:/app/sessions
fabric:/app/auth
fabric:/app/job3
Registered service types
Deployed named service instances
Example: Job Creator application
Job Service Instance 1
Web Service
Service Fabric
Management API
Create
instance
Job Service Instance 2
...
Job Service Instance n
Processing jobs, Game sessions, Tenant accounts, etc.
In-Place Upgrade Options
Production
Cluster
Production
Cluster
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
V2
V1
New Cluster Upgrade Options
Traffic
Manager
Load
Balancer
Production
Cluster
Staging
Cluster
LB
LB
V1 Production
Cluster
V2 Production
Cluster
V1
V1
V2
V2
V1
V1
V2
V2
V1
V1
V2
V2
V1
V1
V2
V2
V1
V1
V2
V2
V1
V1
V2
V2
Comparing Cluster Upgrade Options
Delete
& Upload
Rolling
Upgrade
VIP
Swap
Controlled
Migration
None
None
2x
1x to 2x
Downtime
Reduced scale
Same
Same
Downtime until
V1 upload
Reduced scale
until rollback
Immediate after
swap back
Immediate after
TM reconfig
V2 testability
Not at all
Not at all
Private & Public
Private & Public
Protocol/Schema change
1-Phase
2-Phase
1-Phase
1-Phase
No
Yes
No
No
Add’l Hardware Costs
Service availability
Failed upgrade recovery
Usable with stateful services
•
Some upgrades can be done 1 way and other upgrades another way
Application upgrade
fabric:/JobDemo
JobDemoType 2.0.0
1.0.0
In-place
rolling
upgrade
fabric:/JobDemo-Beta
JobDemoType 2.0.0
fabric:/JobDemo/job1
StatelessJobServiceType 2.0.0
1.0.0
fabric:/JobDemo-Beta/job1
StatelessJobServiceType 2.0.0
fabric:/JobDemo/job2
StatelessJobServiceType 2.0.0
1.0.0
fabric:/JobDemo-Beta/job2
StatelessJobServiceType 2.0.0
New named
application
instance,
side-by-side
Application composition
An application in Service Fabric:
•
•
•
Application composition
A service in Service Fabric:
•
•
•

Application composition
• Named application instances are upgraded individually.
• Named application instances are deleted individually.
• A/B deployments are at the application level.
• Health rolls up to the application.
• Versioning rolls up to the application.
Node Placement Properties & Capacities
• Node Placement Properties & Constraints
 Apply placement properties to all nodes indicating type of RAM, disk, etc.
 Apply placement constraint when starting/updating a named service
• Node Capacities & Service Load Metric Values
 Apply capacity limits to desired nodes indicating size of RAM, disk, etc.
 Specify metrics to balance & default load in ServiceManifest.xml
 Override default load when starting/updating a named service
 A named service instance can report load dynamically with SF prog
models
Service Fabric on Azure
• Built on VM Scale Sets for automatic scale in/out
• Deployable via ARM templates
• Integration with Azure portal
• Automatic upgrade to new runtime releases (optional)
Service Fabric for Windows Server
• Available for Windows Server 2012 R2
• Coming soon for Windows Server 2016
• Securable via X509 certs or Active Directory
• No changes required to application code
Future
• Azure
 VMSS OS upgrades
 Staging for Service Fabric upgrades
• Xplat




Linux
Core CLR support
Java and cross-language support
Open source Service and Actor frameworks
• Application development




Reliable Collections large store support, Reliable Concurrent Queue
ASP.NET Core 1
Visual Studio, tools, CI/CD
Application certificate management
Related
 Microsoft Virtual Academy training videos
 http://bit.do/MicroservicesIntro
 http://bit.do/MicroservicesViaSF
 Demo projects
 Service Fabric demos: https://azure.microsoft.com/enus/resources/samples/?term=service+fabric
 Paolo’s demos: https://github.com/paolosalvatori/
 Job Creator demo: https://github.com/vturecek/job-units-demo
 Cluster Visualizer: https://github.com/vturecek/service-fabric-xray
 Questions? Comments? Issues?
 https://stackoverflow.com/questions/tagged/azure-service-fabric
 https://github.com/azure/service-fabric-issues