A  pattern  language  for  microservices Chris Richardson @crichardson chris@chrisrichardson.net http://eventuate.io
@crichardson About Chris
@crichardson About Chris
@crichardson About Chris http://learnmicroservices.io
@crichardson Why microservices?
@crichardson The monolithic architecture Browser SQL database HTML REST/JSON Client App Catalog Module Reviews Module Orders Module StoreFront UI Module
@crichardson The monolithic architecture Tomcat Browser WAR SQL database HTML REST/JSON Client App Catalog Module Reviews Module Orders Module StoreFront UI Module
@crichardson The monolithic architecture Tomcat Browser WAR SQL database HTML REST/JSON Client App Simple to …. Develop Test Deploy Scale Catalog Module Reviews Module Orders Module StoreFront UI Module
@crichardson But successful applications keep growing ….
@crichardson … and modularity breaks down… http://www.laputan.org/mud/
@crichardson Monolithic hell Agile development and deployment becomes impossible Technology stack becomes increasingly obsolete BUT a rewrite is not feasible
The microservice architecture is an architectural style that structures an application as a set of loosely coupled, services organized around business capabilities
@crichardson Microservices tackles complexity* through modularity Division of labor Division of knowledge
@crichardson Microservices tackles complexity* through modularity Division of labor Division of knowledge * might improve scalability too
@crichardson Microservice architecture = functional decomposition Catalog Service Review Service Order Service … Service
@crichardson Microservice architecture = functional decomposition Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database
@crichardson Microservice architecture = functional decomposition Browser Mobile Device Store Front UI API Gateway Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database HTML REST REST
@crichardson Microservices enable continuous delivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development
@crichardson Microservices enable continuous delivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development Services improve testability and deployability
@crichardson Microservices enable continuous delivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development Services improve testability and deployability Teams own services
@crichardson Easily try other technologies
@crichardson Easily try other technologies ... and fail safely
@crichardson Where does Redis fit in?
Using Redis within a service Caching High performance database Catalog Service Catalog DB
@crichardson Using Redis for inter-service communication API Gateway Catalog Service Review Service … Service Pub/Sub Need Product Details X GET /product/X Need … Need … Need …Info Info Info
@crichardson Redis and the API Gateway API Gateway Caching Rate limiting Routing
@crichardson No silver bullet http://en.wikipedia.org/wiki/Fred_Brooks
@crichardson Drawbacks of microservices Complexity
@crichardson Drawbacks of microservices Complexity Development: IPC, partial failure, distributed data
@crichardson Drawbacks of microservices Complexity Development: IPC, partial failure, distributed data Testing: Integration, end to end, …
@crichardson Drawbacks of microservices Complexity Development: IPC, partial failure, distributed data Testing: Integration, end to end, … Deployment …
@crichardson Are microservices a good fit for my application?
@crichardson When using microservices:
@crichardson When using microservices: How to decompose an application into services? How to deploy an application’s services? How to handle cross cutting concerns? Which communication mechanisms to use? How do external clients communicate with the services? How does a client discover the network location of a service instance? How to prevent a network or service failure from cascading to other services? How to maintain data consistency and implement queries? How to make testing easier? How to understand the behavior of an application and troubleshoot problems? How to implement a UI screen or page that displays data from multiple services?
@crichardson Patterns = Better decisions
@crichardson What’s a pattern? Reusable solution to a problem occurring in a particular context
@crichardson The structure of a pattern encourages objectivity Resulting context Name Context Problem Related patterns Forces Solution
@crichardson The structure of a pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns Forces Solution
@crichardson The structure of a pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution
@crichardson The structure of a pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution Benefits Drawbacks Issues
@crichardson The structure of a pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution Benefits Drawbacks Issues Patterns that are alternative solutions Patterns that address the issues
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardson The rest are generic technical architecture patterns = Undifferentiated heavy lifting!
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardsonMicroservice patterns Communication patterns Core Cross-cutting concerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
@crichardson Solving distributed data management problems in a microservice architecture
@crichardson Loose coupling = encapsulated data Order Service Customer Service Order Database Customer Database Order table Customer table orderTotal creditLimit
@crichardson How to maintain data consistency? sum(order.total) <= customer.creditLimit
@crichardson Cannot use ACID transactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION
@crichardson Cannot use ACID transactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION Private to the Order Service Private to the Customer Service
@crichardson Cannot use ACID transactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION Private to the Order Service Private to the Customer Service Distributed transactions
@crichardson 2PC is not an option
@crichardson Instead: use event-driven sagas Distributed transaction Order
 Service Customer
 Service
@crichardson Saga Instead: use event-driven sagas Distributed transaction Order
 Service Customer
 Service Local transaction Order
 Service Local transaction Customer
 Service Local transaction Order
 Service Event Event X
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Customer creditLimit creditReservations ... Event Handler Event Handler
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Create Order Customer creditLimit creditReservations ... Event Handler Event Handler
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Create Order Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Order created Create Order Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler reserveCredit()
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Order created Credit Reserved Credit Check Failed Create Order OR Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler reserveCredit()
@crichardson Order Service Saga-based, eventually consistent order processing Customer Service Order created Credit Reserved Credit Check Failed Create Order OR Customer creditLimit creditReservations ... Order state total … approve()/reject() Event Handler Event Handler reserveCredit()
@crichardson Service Reliable sagas require atomicity Database Message Broker update publish How to make atomic without 2PC?
@crichardson Event sourcing: event-centric persistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Event type Every state change event
@crichardson Event sourcing: event-centric persistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Event type Order 901101 …OrderCreated Every state change event
@crichardson Event sourcing: event-centric persistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Event type Order 901101 …OrderCreated Every state change event
@crichardson Event sourcing: event-centric persistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Order 903101 …OrderShipped Event type Order 901101 …OrderCreated Every state change event
@crichardson How to implement queries?
@crichardson How to find recent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ?
@crichardson How to find recent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service
@crichardson How to find recent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service What if event sourcing is used?
@crichardson How to find recent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service What if event sourcing is used?…. is no longer easy
@crichardson Query side (Materialized) View Command Query Responsibility Segregation (CQRS) Command side Commands Aggregate Queries (Materialized) View POST PUT DELETE GET
@crichardson Query side (Materialized) View Command Query Responsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Queries (Materialized) View POST PUT DELETE GET
@crichardson Query side (Materialized) View Command Query Responsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Queries (Materialized) View Events POST PUT DELETE GET
@crichardson Food to Go example - on github.com http://bit.ly/redis-pia 94619:Monday [0700_2:1430, 1130_1:1430, ...] 94619:Tuesday [0700_2:1430, 1130_1:1430, ...] … … Restaurant View Updater Service Restaurant View Query Service ZRANGEBYSCORE Event Store Restaurant events Materialized view of restaurant locations and opening hours GET available restaurants ZADD ZREM Sorted sets
@crichardson Summary
@crichardson Summary Organize into small, agile, autonomous teams responsible for one or more microservices
@crichardson Summary Organize into small, agile, autonomous teams responsible for one or more microservices Use an event-driven architecture based on event sourcing and CQRS
@crichardson Summary Organize into small, agile, autonomous teams responsible for one or more microservices Use an event-driven architecture based on event sourcing and CQRS Use Redis throughout a microservices architecture
Thank  You Chris  Richardson   Founder   http://eventuate.io   #redisconf17

RedisConf17 - A pattern language for microservices - Chris Richardson

  • 1.
    A  pattern  language  for  microservices Chris Richardson @crichardson chris@chrisrichardson.net http://eventuate.io
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
    @crichardson The monolithic architecture Tomcat Browser WAR SQL database HTML REST/JSON Client App Simpleto …. Develop Test Deploy Scale Catalog Module Reviews Module Orders Module StoreFront UI Module
  • 9.
  • 10.
    @crichardson … and modularitybreaks down… http://www.laputan.org/mud/
  • 11.
    @crichardson Monolithic hell Agile developmentand deployment becomes impossible Technology stack becomes increasingly obsolete BUT a rewrite is not feasible
  • 12.
    The microservice architectureis an architectural style that structures an application as a set of loosely coupled, services organized around business capabilities
  • 13.
    @crichardson Microservices tackles complexity*through modularity Division of labor Division of knowledge
  • 14.
    @crichardson Microservices tackles complexity*through modularity Division of labor Division of knowledge * might improve scalability too
  • 15.
    @crichardson Microservice architecture =functional decomposition Catalog Service Review Service Order Service … Service
  • 16.
    @crichardson Microservice architecture =functional decomposition Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database
  • 17.
    @crichardson Microservice architecture =functional decomposition Browser Mobile Device Store Front UI API Gateway Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database HTML REST REST
  • 18.
    @crichardson Microservices enable continuousdelivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development
  • 19.
    @crichardson Microservices enable continuousdelivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development Services improve testability and deployability
  • 20.
    @crichardson Microservices enable continuousdelivery and deployment Process: Continuous delivery/deployment Organization: Small, agile, autonomous, cross functional teams Architecture: Microservice architecture Enables Enables Enables Successful Software Development Services improve testability and deployability Teams own services
  • 21.
  • 22.
    @crichardson Easily try othertechnologies ... and fail safely
  • 23.
  • 24.
    Using Redis withina service Caching High performance database Catalog Service Catalog DB
  • 25.
    @crichardson Using Redis forinter-service communication API Gateway Catalog Service Review Service … Service Pub/Sub Need Product Details X GET /product/X Need … Need … Need …Info Info Info
  • 26.
    @crichardson Redis and theAPI Gateway API Gateway Caching Rate limiting Routing
  • 27.
  • 28.
  • 29.
  • 30.
    @crichardson Drawbacks of microservices Complexity Development:IPC, partial failure, distributed data Testing: Integration, end to end, …
  • 31.
    @crichardson Drawbacks of microservices Complexity Development:IPC, partial failure, distributed data Testing: Integration, end to end, … Deployment …
  • 32.
    @crichardson Are microservices agood fit for my application?
  • 33.
  • 34.
    @crichardson When using microservices: Howto decompose an application into services? How to deploy an application’s services? How to handle cross cutting concerns? Which communication mechanisms to use? How do external clients communicate with the services? How does a client discover the network location of a service instance? How to prevent a network or service failure from cascading to other services? How to maintain data consistency and implement queries? How to make testing easier? How to understand the behavior of an application and troubleshoot problems? How to implement a UI screen or page that displays data from multiple services?
  • 35.
  • 36.
    @crichardson What’s a pattern? Reusablesolution to a problem occurring in a particular context
  • 37.
    @crichardson The structure ofa pattern encourages objectivity Resulting context Name Context Problem Related patterns Forces Solution
  • 38.
    @crichardson The structure ofa pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns Forces Solution
  • 39.
    @crichardson The structure ofa pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution
  • 40.
    @crichardson The structure ofa pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution Benefits Drawbacks Issues
  • 41.
    @crichardson The structure ofa pattern encourages objectivity Resulting context The situation Name Context Problem Related patterns The issues that must be addressed Forces Solution Benefits Drawbacks Issues Patterns that are alternative solutions Patterns that address the issues
  • 42.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 43.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 44.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 45.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 46.
    @crichardson The rest aregeneric technical architecture patterns = Undifferentiated heavy lifting!
  • 47.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 48.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 49.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 50.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 51.
    @crichardsonMicroservice patterns Communication patterns Core Cross-cuttingconcerns Security Deployment Maintaining data consistency Database architecture External API Reliability Discovery Communication style Testing Observability UI Decomposition API gateway Client-side discovery Server-side discovery Service registry Self registration 3rd party registration Multiple Services per host Single Service per Host Service-per- Container Service-per-VM Messaging Remote Procedure Invocation Database per Service Event-driven architectureShared database Microservice Chassis Backend for front end Event sourcing Transaction log tailing Database triggers Application events Monolithic architecture Microservice architecture CQRS Motivating Pattern Solution Pattern Solution A Solution B General Specific Serverless deployment Circuit BreakerAccess Token Domain-specific Externalized configuration Service Integration Contract Test Service Component Test Exception tracking Distributed tracing Audit logging Application metrics Log aggregation Health check API Service deployment platform Server-side page fragment composition Client-side UI composition Decompose by business capability Decompose by subdomain Application patterns Infrastructure patterns Application Infrastructure patterns Microservices pattern language: http://microservices.io
  • 52.
    @crichardson Solving distributed datamanagement problems in a microservice architecture
  • 53.
    @crichardson Loose coupling =encapsulated data Order Service Customer Service Order Database Customer Database Order table Customer table orderTotal creditLimit
  • 54.
    @crichardson How to maintaindata consistency? sum(order.total) <= customer.creditLimit
  • 55.
    @crichardson Cannot use ACIDtransactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION
  • 56.
    @crichardson Cannot use ACIDtransactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION Private to the Order Service Private to the Customer Service
  • 57.
    @crichardson Cannot use ACIDtransactions BEGIN TRANSACTION … SELECT ORDER_TOTAL FROM ORDERS WHERE CUSTOMER_ID = ? … SELECT CREDIT_LIMIT FROM CUSTOMERS WHERE CUSTOMER_ID = ? … INSERT INTO ORDERS … … COMMIT TRANSACTION Private to the Order Service Private to the Customer Service Distributed transactions
  • 58.
  • 59.
    @crichardson Instead: use event-drivensagas Distributed transaction Order
 Service Customer
 Service
  • 60.
    @crichardson Saga Instead: use event-drivensagas Distributed transaction Order
 Service Customer
 Service Local transaction Order
 Service Local transaction Customer
 Service Local transaction Order
 Service Event Event X
  • 61.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Customer creditLimit creditReservations ... Event Handler Event Handler
  • 62.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Create Order Customer creditLimit creditReservations ... Event Handler Event Handler
  • 63.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Create Order Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler
  • 64.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Order created Create Order Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler reserveCredit()
  • 65.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Order created Credit Reserved Credit Check Failed Create Order OR Customer creditLimit creditReservations ... Order state total … Event Handler Event Handler reserveCredit()
  • 66.
    @crichardson Order Service Saga-based, eventuallyconsistent order processing Customer Service Order created Credit Reserved Credit Check Failed Create Order OR Customer creditLimit creditReservations ... Order state total … approve()/reject() Event Handler Event Handler reserveCredit()
  • 67.
    @crichardson Service Reliable sagas requireatomicity Database Message Broker update publish How to make atomic without 2PC?
  • 68.
    @crichardson Event sourcing: event-centricpersistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Event type Every state change event
  • 69.
    @crichardson Event sourcing: event-centricpersistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Event type Order 901101 …OrderCreated Every state change event
  • 70.
    @crichardson Event sourcing: event-centricpersistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Event type Order 901101 …OrderCreated Every state change event
  • 71.
    @crichardson Event sourcing: event-centricpersistence Service Event Store save events and publish Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Order 903101 …OrderShipped Event type Order 901101 …OrderCreated Every state change event
  • 72.
  • 73.
    @crichardson How to findrecent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ?
  • 74.
    @crichardson How to findrecent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service
  • 75.
    @crichardson How to findrecent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service What if event sourcing is used?
  • 76.
    @crichardson How to findrecent, valuable customers? SELECT * FROM CUSTOMER c, ORDER o WHERE c.id = o.ID AND o.ORDER_TOTAL > 100000 AND o.STATE = 'SHIPPED' AND c.CREATION_DATE > ? Customer Service Order Service What if event sourcing is used?…. is no longer easy
  • 77.
    @crichardson Query side (Materialized) View Command QueryResponsibility Segregation (CQRS) Command side Commands Aggregate Queries (Materialized) View POST PUT DELETE GET
  • 78.
    @crichardson Query side (Materialized) View Command QueryResponsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Queries (Materialized) View POST PUT DELETE GET
  • 79.
    @crichardson Query side (Materialized) View Command QueryResponsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Queries (Materialized) View Events POST PUT DELETE GET
  • 80.
    @crichardson Food to Goexample - on github.com http://bit.ly/redis-pia 94619:Monday [0700_2:1430, 1130_1:1430, ...] 94619:Tuesday [0700_2:1430, 1130_1:1430, ...] … … Restaurant View Updater Service Restaurant View Query Service ZRANGEBYSCORE Event Store Restaurant events Materialized view of restaurant locations and opening hours GET available restaurants ZADD ZREM Sorted sets
  • 81.
  • 82.
    @crichardson Summary Organize into small,agile, autonomous teams responsible for one or more microservices
  • 83.
    @crichardson Summary Organize into small,agile, autonomous teams responsible for one or more microservices Use an event-driven architecture based on event sourcing and CQRS
  • 84.
    @crichardson Summary Organize into small,agile, autonomous teams responsible for one or more microservices Use an event-driven architecture based on event sourcing and CQRS Use Redis throughout a microservices architecture
  • 85.
    Thank  You Chris  Richardson   Founder   http://eventuate.io   #redisconf17