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: https://github.com/eventuate-examples/eventuate-examples-restaurant-management
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
Microservices and Redis #redisconf Keynote
1. Microservices and Redis
Chris Richardson
Founder of Eventuate.io
Founder of the original CloudFoundry.com
Author of POJOs in Action
@crichardson
chris@chrisrichardson.net
http://eventuate.io
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
12. Using Redis within a service
Caching
High performance messaging
High performance database
Catalog
Service
Catalog
DB
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
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 order.total) <= customer.creditLimit
?
18. @crichardson
Use event-driven, eventually consistent order
processing
Order
Service
Customer
Service
Order created
Credit Reserved
Credit Check Failed
Place Order
OR
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
?
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
23. @crichardson
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
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. @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
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