Microservices
By
Subhashish Bhattacharjee
Outline
Intro to Microservices
Microservices Design Principles
Microservices tech stack
Refactoring a Monolithic app to Microservices
Real world example of Microservices
What is a Service?
 A service is a discrete unit of software which basically gives functionality to
other pieces of software within the system. It can be used and updated
independently.
 A service can be reused by different clients, e.g. a mobile & a desktop app.
 Services can be used in conjunction to provide the functionality of a large
software application.
 Services communicate with each other over the network.
Service-Oriented Architecture (SOA)
 It logically represents a business activity with a specified outcome.
 It is self-contained.
 It is a black box for its consumers.
 It may consist of other underlying services.
Source: wikipedia
Monolithic Apps
 Traditional enterprise applications, such as a large e-commerce
website.
 All modules packaged together as a single unit.
 Can be a large service.
 Single executable.
 Shared libraries.
An example of Monolithic app
Source: microservices.io
Limitations of monolithic apps
 Large code base intimidates developers especially ones who are
new to the team
 Lack of agility
 Longer startup time due to large size of the application
 Scaling requires whole application to scale thereby requiring more
computing resources
 Does not fit into DevOps cycles
Definition of microservices
Scope of Microservices
A picture is worth a thousand
words
A Succinct Definition
“Service-oriented architecture”
Composed of
“loosely-coupled components”
Which have
“bounded contexts.”
 By Adrian Cockcroft, VP Cloud Architecture Strategy at AWS (source: Dockercon Europe, 2014)
“do one thing, and do it well”
Each component in the Swiss
army knife does a specific job
Benefits of Microservices
 Independent scaling
• Each microservice can scale independently
 Independent Upgrades
• Each microservice can be deployed independently of other services.
 Ease of maintenance
• Smaller code base focusing on only one thing eases maintenance of code.
 Polyglot
• Developers are free to use the language of their choice for each microservice
independently.
Other benefits
 Fault isolation
• A fault such as memory leak or unclosed database connection is confined to
the particular microservice in question and doesn’t impact the whole system.
 Improved Communication across development teams
• Communication is improved as smaller teams are focused to deliver product
pertaining to a particular business domain.
 Central logging and monitoring
• A central logging system as well as a monitoring system can help analyze
logs for possible issues and also alert the team in case a threshold has been
reached.
 Benefits of embracing CI/CD
• Continuous integration and continuous deployment help in code integration
and deployment in a seamless manner without any manual intervention.
Microservices Design Principles
High Cohesion Autonomous Business Domain-Driven
Resilience Observable Automation
High Cohesion
Accounts
Service
Orders
Service
Products
Service
Inventory
Service
Shipping
Service
 Single focus
 Single Responsibility
Characteristics based on above
two properties:
 Can be easily rewritten
 Scalable
 Flexible
 Reliable
Autonomous
Accounts
Service
Orders
Service
Products
Service
Inventory
Service
Shipping
Service
 Loose Coupling
 Honor common interfaces
 Stateless
 Independently Changeable
 Independently deployable
 Parallel development
Business Domain-Driven
Accounts
Service
Orders
Service
Products
Service
Inventory
Service
Shipping
Service
 Should represent business
function
 Scope of service
 Clearly defined boundaries
 Group related logic together
 Responsive to change in
business domain
Resilience
Accounts
Service
Orders
Service
Products
Service
Inventory
Service
Shipping
Service
 Failure is unavoidable
 Responds well when failure
occurs
 Degrade functionality
 Default functionality
Observable
 Centralized monitoring
• Application health
• Distributed transaction monitoring
 Centralized Logging
• Logs
• Errors
Automation
 Tools to reduce manual testing
 Tools to provide feedback
 Tools to provide automated deployment
Use of Microservices in Cloud
 Easy deployment
 Software isolation with containers
 Easy scaling
 Automated logging
 API Gateway
 Registration and discovery
Microservices Tech Stack
Synchronous Communication
1. Make a call
2. Wait for response
3. Received response
Client
1. Request received
2. Do some work
3. Send response
Server
1. Request response model
2. HTTP
• De facto standard of the web
• Supports serialization of
XML/JSON/Protobuf
3. REST
• CRUD using HTTP verbs
• Open communication protocol
• Decoupled by nature
4. Synchronous communication issues
• Both client and server are to be available
• Performance depends on network
• Client must know the location of server
HTTP
JSON
Asynchronous Communication
 Removes the criteria of client and server availability
 Decouples client and service
 Use of message brokers to send and receive messages by producers and subscribers,
such as RabbitMQ, Kafka etc.
 Architecture becomes complicated.
 Heavy reliance on the message broker for the proper functioning of the system.
 Extra logic for managing the message queue for publishing and consuming messages.
Virtualization
Containers
Registration & Discovery
 Location?
• Host, port, version etc.
 Database for service registration
 Register on startup
 Deregister on failure
 Client side discovery
 Server side discovery
Monitoring
 New Relic
 Nagios
Logging
 Logstash
 Splunk
 Graphite
Scaling
 Vertical scaling
 Horizontal scaling
 Scale application or load balancer automated or on-demand.
 PaaS platforms make scaling a breeze.
API Gateway
 Central entry point
 API gateway provides stronger security
 Dedicated security service
 Centralized security for microservices
Automation tools
 Jenkin
 CircleCI
 Travis
Refactoring a monolith app to
microservices
Monolithic Architecture
Source: microservices.io
Microservice Architecture
Source: microservices.io
Challenges with Microservices
 Being a distributed system has its intrinsic challenges
 Complexity due to many teams and synchronization among teams
 Complexity dealing with asynchronous calls
 Cascading failures
 Discovery and authentication of services
 Integration testing
 Duplication of processes and tools
 Debugging across components
Real World example of Microservices
• Go to www.amazon.com and try to find out as many microservices that you can observe on the home
page.
References
 http://microservices.io
 Microservices Architecture by Rag Dhiman (www.pluralsight.com)
 Building Microservices by Sam Newman
THANK YOU

Microservices-101