Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Microservices in a message-based world

Microservices in a message-based world

Microservices is not something you can buy and install, it's not a ready-to-use software, but a set of principles for building low-coupled distributed systems. Principles that marry well with today business needs and that to be effective they must be accepted along with the changes they bring. In this session we will see what it means to "live in a Microservices world" and how its introduction will change our way of thinking and applying.

Manuel Scapolan

May 09, 2015
Tweet

More Decks by Manuel Scapolan

Other Decks in Programming

Transcript

  1. Enterprise Applications Usually • involve persistent data There • ’s

    usually a lot of data Usually • many people access data concurrently There • ’s usually a lot of user interface screen Usually • they need to integrate with other enterprise applications What • about “business logic”? from Patterns of Enterprise Application Architecture (PoEAA - Martin Fowler)
  2. Monolithic Architecture • Simple to develop • Simple to test

    • Simple to deploy • Simple to scale Business Layer Presentation Layer Data Layer A good starting point… user
  3. Until it grows… • Large code intimidates developers • Small

    change – big impact • Long term commitment to technology stack • Little resilience to failure • Scaling can be difficult
  4. Vertical scaling • Adding more hardware… – CPU/core – RAM

    – … Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer
  5. Horizontal scaling • Running multiple identical copies of the application

    behind a load balancer Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer
  6. Data partitioning Each • server runs an identical copy of

    the code Each • server is responsible for only a subset of the data (i.e. sharding) Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer data segment data segment data segment
  7. Functional decomposition • Splits a monolithic application into a set

    of services (or microservices) A B A B Microservices Traditional development model
  8. Microservices Service-oriented architecture composed of loosely coupled elements that have

    bounded contexts. Is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. James Lewis and Martin Fowler - ThoughtWorks Adrian Cockcroft – Cloud Architect at Netflix
  9. Characteristics of Microservices • Small (how much?) • Built around

    business capabilities (bounded context) • Independently deployable • Little centralized management • Smart end-points and dumb pipes • Lack of centralized, shared database
  10. Classic SOA • Integrates different applications as a set of

    services WS* WS* WS* WS* WS* WS* WS* WS* Enterprise Service Bus
  11. Microservices architecture Architect a single • application as a set

    of services Backends Catalog service Ordering service Inventory service API API API Customer service Accounting service API
  12. Synchronous HTTP • As REST or SOAP Request/ + reply

    Firewall + friendly Doesn – ’t support publish-subscribe Both – the client and the server must be simultaneously available HTTP clients – needs to know host and port of the server
  13. Asynchronous messaging • As an AMQP-based message broker or a

    message bus + Support one-way requests and publish-subscribe + Producers are completely unaware of the consumers – Request-reply style is not a natural fit – Another moving part that add complexity to the system
  14. Communication issues • The granularity of APIs provided by microservices

    is often different than what a client needs • Different clients need different data • The number of service instances and their locations (host+port) changes dynamically • Partitioning into services can change over time and should be hidden from clients
  15. API gateway • Single entry point for all clients •

    Some requests are proxied/routed to the appropriate service • It handles other requests by fanning out to multiple services API gateway Service A Service B Service C Service D REST REST REST AMQP Protocol transaltion
  16. Handling reads Order Service Customer Service PlaceOrder() VerifyCreditLimit() SaveOrder() The

    Customer Service must be running in order to place the order Calling thread is waiting for the result
  17. Handling reads (another approach) Order Service Customer Service PlaceOrder() CreditLimitUpdated

    SaveOrder() The Order Service stores a local copy of the credit limit StoreCreditLimit()
  18. Handling update requests • Distributed transactions  + Ensure that

    the data is always consistent – Reduce availability since all participants must be available in order for the transactions to commit – Not supported by modern stacks, e.g. REST, NoSQL databases, etc.
  19. Handling update requests • Event-driven asynchronous updates Message broker/bus Customer

    Service Order Service UpdateCreditLimit() CreditLimitUpdatedEvent CreditLimitUpdatedEvent
  20. Handling update requests • Event-driven asynchronous updates ☺ + If

    a consumer isn’t available to process an event then the message broker/bus will queue the event until it can – The application has to be written in a way that can tolerate eventually consistent data – Developers might also need to implement compensating transactions to perform logical rollbacks
  21. Conway’s Law If the architecture of the system and the

    architecture of the organization are at odds, the architecture of the organization wins. Organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations. Mel Conway, 1968 Ruth Malan, 2008 and
  22. Microservices model • A team handles all aspects of software

    development for the microservice, from conception through deployment Source: Adam Cockcroft
  23. Handling failures Services can • fail at any moment Design

    • services to handle these • kind of failures Pattern: • circuit breaker, tolerant reader, bulkheads, timeouts, … Generating • failures with a “Chaos Monkey” Circuit Breaker - martinfowler.com
  24. Refactoring a monolith • Stop implementing significant new functionality by

    adding code to the monolith • Find a way to implement new functionality as a standalone service • You will have to write messy, complex glue code Monolith New Service Glue code
  25. Benefits of Microservices • Increase the autonomy of development teams

    • Aids the adoption of new technologies • Speed of change, and speed of responding to new opportunities with new services • Allow a fine-grained approach to performance tuning or scaling
  26. Microservices drawbacks • Catastrophic failure • Significant Operations Overhead •

    Substantial Devops Skills Required • Implicit Interfaces • Asynchronicity Is Difficult!
  27. Resources Microservices • [http://martinfowler.com/articles/microservices.html] InfoQ • eMag: Microservices [http://www.infoq.com/minibooks/emag-microservices] Udi

    • Dahan on Defining Service Boundaries [http://www.infoq.com/news/2015/02/service-boundaries-healthcare] SOA, EDA, and CEP a • winning combo [http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/] Event • -Driven Architecture (EDA), SOA, and DDD with Udi Dahan [https://vimeo.com/57644944] Evolutionary • Architecture and Microservices [http://www.infoq.com/presentations/evolutionary-architecture-microservices-cd] MicroServices • , yet another architectural style? [http://www.slideshare.net/aca_it/micro-services-40695502] Exploring • Microservices [https://xebialabs.com/assets/files/whitepapers/Microservices%20Whitepaper.pdf] Practical • Implications of Microservices in 14 Tips [http://www.infoq.com/articles/microservices-practical-tips] The • Role of Containers in Modern Applications [http://www.infoq.com/articles/roundtable-containers-microservices] Why • I love Docker [http://blog.thomasqvarnstrom.com/2015/01/why-i-love-docker.html] Centralised • vs. Decentralised Data [http://bill-poole.blogspot.it/2008/02/centralised-vs-decentralised-data.html] Cover image • [https://www.flickr.com/photos/matthewgriff/3434441969/]