Microservices Basics
Microservices Basics
– Advantages
– Problems
▪ Microservices Architecture
– What is MSA?
– Identify Microservices
– Microservices patterns
– Technologies Stack
– Known uses
▪ Links/References
▪ Questions
2 Internal
Monolithic Architecture
4 Internal
Monolithic Architecture: Problems
5 Internal
Monolithic Architecture: Problems
6 Internal
Monolithic Architecture: Problems
7 Internal
Monolithic Architecture: Problems
8 Internal
From Monolithic towards Microservices Architecture
▪ Microservices - also known as the microservice architecture - is an architectural style that structures an
application as a collection of services that are
– Highly maintainable and testable
– Loosely coupled
– Independently deployable
– Organized around business capabilities
– Owned by a small team
▪ The microservice architecture enables the rapid, frequent and reliable delivery of large, complex
applications. It also enables an organization to evolve its technology stack.
▪ Libraries as components that are linked into a program and called using in-memory function calls,
while services are out-of-process components who communicate with a mechanism such as a web
service request, or remote procedure call.
▪ Services are independently deployable. If you have an application that consists of a multiple libraries in a
single process, a change to any single component results in having to redeploy the entire application. But
if that application is decomposed into multiple services, you can expect many single service changes to
only require that service to be redeployed.
▪ Downsides? - Remote calls are more expensive than in-process calls
Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of
the organization's communication structure.
-- Melvyn Conway, 1967
▪ Microservice approach to division is different, splitting up into services organized around business
capability. Such services take a broad-stack implementation of software for that business area, including
user-interface, persistent storage, and any external collaborations.
▪ Consequently the teams are cross-functional, including the full range of skills required for the
development: user-experience, database, and project management.
▪ Project model -> where the aim is to deliver some piece of software which is then considered to be
completed. On completion the software is handed over to a maintenance organization and the project
team that built it is disbanded.
▪ Microservice -> a team should own a product over its full lifetime.
▪ Amazon's notion of "you build, you run it" - where a development team takes full responsibility for the
software in production.
▪ This brings developers into day-to-day contact with how their software behaves in production and
increases contact with their users, as they have to take on at least some of the support burden.
▪ The product mentality, ties in with the linkage to business capabilities. Rather than looking at the
software as a set of functionality to be completed, there is an on-going relationship where the question
is how can software assist its users to enhance the business capability.
▪ Enterprise Service Bus (ESB) - ESB products often include sophisticated facilities for message routing,
choreography, transformation, and applying business rules.
▪ Microservice -> Applications built from microservices aim to be as decoupled and as cohesive as possible
- they own their own domain logic and act more as filters in the classical Unix sense - receiving a request,
applying logic as appropriate and producing a response.
▪ These are choreographed using simple RESTish protocols (HTTP request-response)
▪ Lightweight message bus -> The infrastructure chosen is typically dumb (dumb as in acts as a message
router only) - simple implementations such as RabbitMQ or ZeroMQ don't do much more than provide a
reliable asynchronous fabric - the smarts still live in the end points that are producing and consuming
messages; in the services.
▪ Monolithic applications -> prefer a single logical database for persistent data, enterprises often prefer a
single database across a range of applications - many of these decisions driven through vendor's
commercial models around licensing.
▪ Microservices -> prefer letting each service manage its own database, either different instances of the
same database technology, or entirely different database systems.
▪ Polyglot Persistence
▪ Services can fail at any time, it's important to be able to detect the failures quickly and, if possible,
automatically restore service.
▪ Emphasis on real-time monitoring of the application, checking both architectural elements (how many
requests per second is the database getting) and business relevant metrics (such as how many orders per
minute are received).
▪ Semantic monitoring can provide an early warning system of something going wrong that triggers
development teams to follow up and investigate.
▪ Microservice teams would expect to see sophisticated monitoring and logging setups for each individual
service such as dashboards showing up/down status and a variety of operational and business relevant
metrics.
▪ Details on circuit breaker status, current throughput and latency are other examples often encounter.
23 Internal
Identifying Microservices – Bounded contexts
24 Internal
Domain Driven Design
Source: https://learning.oreilly.com/library/view/domain-
driven-design-tackling/0321125215/ 25 Internal
Communication between Microservices
▪ Synchronous communication
– In this pattern, a service calls an API that another service exposes, using a protocol
such as HTTP or gRPC. This option is a synchronous messaging pattern because the
caller waits for a response from the receiver.
▪ Asynchronous messaging
– In this pattern, a service sends message without waiting for a response, and one or
more services process the message asynchronously.
Source: https://docs.microsoft.com/en-
us/azure/architecture/microservices/design/interservice-
communication 26 Internal
Asynchronous messaging
Advantages Challenges
▪ Reduced coupling ▪ Coupling with the messaging
▪ Multiple subscribers infrastructure
▪ Failure isolation ▪ Latency
▪ Responsiveness ▪ Cost
▪ Load leveling ▪ Complexity
▪ Workflows ▪ Throughput
Source: https://docs.microsoft.com/en-
us/azure/architecture/microservices/design/interservice-
communication 27 Internal
Example - e-commerce application
▪ Configuration Management
▪ Service Discovery & Load Balancing
▪ Resilience & Fault Tolerance
▪ API Management
▪ Service Security
▪ Centralized Logging
▪ Centralized Metrics
▪ Distributed Tracing
▪ Scheduling & Deployment
▪ Auto Scaling and Self Healing
30
Patterns
32 Internal
Patterns - Contnd
▪ Observability
– Log aggregation
– Application metrics
– Audit logging
– Distributed tracing
– Exception tracking
– Health check API
– Log deployments and changes
▪ UI patterns
– Server-side page fragment composition
– Client-side UI composition
33 Internal
API Gateway
34 Internal
API Gateway - Routing
35 Internal
API Gateway – Load Balancer
36 Internal
Configuration management
▪ Scattered Configuration
37 Internal
Configuration management
▪ Centralized Configuration
38 Internal
Service Discovery
39 Internal
Service Discovery
40 Internal
Building resilient Microservices
41 Internal
Technology Stack for Microservices
42
Spring Cloud + Netflix OSS
Microservices Concern Tools
Configuration Management Spring Cloud Config Server, Consul
Service Discovery Netflix Eureka
API Gateway Netflix Zuul
Load Balancer Netflix Ribbon
Monitoring Netflix Hystrix dashboard, Turbine
Security Spring Cloud Security
Centralized Logging ELK Stack (Logstash)
Centralized Metrics Netflix Spectator and Atlas
Distributed Tracing Spring Cloud Sleuth and Zipkin
Resilience & Fault Tolerance Netflix Hystrix (Circuit Breaker), Turbine & Ribbon
Packaging & Deployment Spring Boot
44 Internal
Known uses
45
Companies using Microservices
▪ Netflix
▪ Amazon
▪ Ebay
▪ Uber
▪ Comcast Cable
▪ Sound Cloud
▪ Karma
▪ Groupon
▪ Hailo
▪ Gilt
▪ Zalando
▪ Capital One Why Capital One is at Re:Invent and Keynote
▪ Lending Club
▪ AutoScout24
47
Reference links
▪ https://microservices.io/
▪ https://martinfowler.com/microservices/
▪ https://12factor.net/
▪ https://spring.io/projects/spring-cloud-netflix
▪ https://aws.amazon.com/microservices/
▪ https://docs.microsoft.com/en-us/azure/architecture/microservices/
48 Internal
Thank You
49
Backup Slides
50
The Twelve Factors