Slide 1

Slide 1 text

MICROSERVICES IN A MESSAGE-BASED WORLD Software Architect at ServiziCGN @manuelscapolan Manuel Scapolan

Slide 2

Slide 2 text

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)

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

Vertical scaling • Adding more hardware… – CPU/core – RAM – … Business Layer Presentation Layer Data Layer Business Layer Presentation Layer Data Layer

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Functional decomposition • Splits a monolithic application into a set of services (or microservices) A B A B Microservices Traditional development model

Slide 9

Slide 9 text

What are microservices?

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

A modern SOA?

Slide 13

Slide 13 text

Classic SOA • Integrates different applications as a set of services WS* WS* WS* WS* WS* WS* WS* WS* Enterprise Service Bus

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

Microservices at Netflix

Slide 16

Slide 16 text

Communication mechanisms in a microservice architecture smart endpoints and dumb pipes

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Decentralized data management each service has its own database (schema)

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Handling reads (another approach) Order Service Customer Service PlaceOrder() CreditLimitUpdated SaveOrder() The Order Service stores a local copy of the credit limit StoreCreditLimit()

Slide 24

Slide 24 text

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.

Slide 25

Slide 25 text

Handling update requests • Event-driven asynchronous updates Message broker/bus Customer Service Order Service UpdateCreditLimit() CreditLimitUpdatedEvent CreditLimitUpdatedEvent

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Organization & agile practices

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Traditional team structure Separate silos • Source: Adam Cockcroft

Slide 30

Slide 30 text

Microservices model • A team handles all aspects of software development for the microservice, from conception through deployment Source: Adam Cockcroft

Slide 31

Slide 31 text

Microservices & DevOps

Slide 32

Slide 32 text

The role of Containers • Create small independent deployments

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

How to get started

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

In summary…

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Microservices drawbacks • Catastrophic failure • Significant Operations Overhead • Substantial Devops Skills Required • Implicit Interfaces • Asynchronicity Is Difficult!

Slide 39

Slide 39 text

To learn more about Microservices, Messaging system, DevOps,…

Slide 40

Slide 40 text

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/]

Slide 41

Slide 41 text

Thank you @manuelscapolan