Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Microservices and Redis #redisconf Keynote


Published on

This is a keynote talk that I gave at RedisConf 2016.
It answers three questions:
What are microservices?
Why should you use them?
Where does Redis fit into a microservices architecture?

You can find the example code here:

Published in: Software

Microservices and Redis #redisconf Keynote

  1. 1. Microservices and Redis Chris Richardson Founder of Founder of the original Author of POJOs in Action @crichardson
  2. 2. @crichardson About Chris
  3. 3. @crichardson Why microservices?
  4. 4. @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
  5. 5. @crichardson But successful applications keep growing …. Eventually, agile development and deployment becomes impossible
  6. 6. @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
  7. 7. @crichardson Develop and deploy faster
  8. 8. @crichardson Scale more easily
  9. 9. @crichardson Pick the best technology
  10. 10. @crichardson Microservices are not a free lunch BUT for most large, complex applications are good choice
  11. 11. @crichardson Where does Redis fit in?
  12. 12. Using Redis within a service Caching High performance messaging High performance database Catalog Service Catalog DB
  13. 13. @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
  14. 14. @crichardson Redis and the API Gateway API Gateway Caching Rate limiting Routing
  15. 15. @crichardson How to maintain data consistency?
  16. 16. @crichardson Database per service Catalog Service Review Service Order Service … Service Catalog Database Review Database Order Database … Database How to maintain data consistency without 2PC?
  17. 17. @crichardson Customer DB How to maintain data consistency without 2PC? Order DB Order Service placeOrder() Customer Service updateCreditLimit() Customer creditLimit ... has ordersbelongs toOrder total Invariant: sum(open <= customer.creditLimit ?
  18. 18. @crichardson Use event-driven, eventually consistent order processing Order Service Customer Service Order created Credit Reserved Credit Check Failed Place Order OR
  19. 19. @crichardson How to atomically update database and publish an event without 2PC? Order Service Order Database Message Broker insert Order publish OrderCreatedEvent dual write problem ?
  20. 20. @crichardson Use event sourcing Order Service Order Database Event Store insert Order Save OrderCreatedEvent X Persistence and notification
  21. 21. @crichardson Event sourcing: persists events NOT current state Event table Entity type Event id Entity id Event data Order 902101 …OrderApproved Order 903101 …OrderShipped Event type Order 901101 …OrderCreated Order state total Replay
  22. 22. @crichardson How to implement queries?
  23. 23. @crichardson Find recent, valuable customers SELECT * FROM CUSTOMER c, ORDER o WHERE = 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
  24. 24. @crichardson Command Query Responsibility Segregation (CQRS) Command side Commands Aggregate Event Store Events Query side Queries Materialized View Events POST PUT DELETE GET
  25. 25. @crichardson Food to Go example - on 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
  26. 26. @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
  27. 27. Thank you! @crichardson