SlideShare a Scribd company logo
Scalable Microservices with
Event Sourcing and Redis
Tom Mooney
Learning.com
Microservices
Communication Between Services
Client
Order
Service
Customer
Service
Invoice
Service
Inventory
Service
CAP Theorem
It is impossible for a distributed system to
simultaneously provide more than two out of the
following three guarantees
• Consistency
• Every read receives the most recent write or an error
• Availability
• Every request receives a (non-error) response – without guarantee
that it contains the most recent write
• Partition Tolerance
• The system continues to operate despite an arbitrary number of
messages being dropped (or delayed) by the network between
nodes
Event Driven Services
Client
Order
Service
Customer
Service
Inventory
Service
Event
Bus
Message
Queue
Create Order
OrderCreated
OrderCreated
OrderCreated
Why Redis?
There are many choices of tools for implementing a
messaging system including Apache Kafka or more
traditional messaging systems like RabbitMQ.
• With it’s built in pub/sub functionality Redis can be
used as a perfectly capable message queue.
• It’s already in use in many organizations so existing
infrastructure can be used which lowers both
implementation costs as well as ongoing support
costs.
Redis Message Queue
Event Sourcing
Redis Event Store
CQRS
Command Query Responsibility Segregation
Client
Commands Projections (Queries)
Events
Lessons Learned
• Event Sourcing is not always the right solution, in fact
it usually isn’t.
• Has to be the right kinds of data
• Most of the time a using a simpler message queue is better
• Storing event data in Redis is expensive and it’s hard
to query
• We have moved to storing event data in Postgres and just using
Redis as the messaging layer.
• If cost isn’t an issue, the query problem can probably be solved
with ReJSON.
Distributed systems are hard…
But making services event driven with Redis, CQRS, and Event Sourcing can help
Code
• https://github.com/learningcom/Learning.EventStore
Thank You

More Related Content

What's hot (20)

PPTX
RedisConf18 - Serving Automated Home Valuation with Redis & Kafka
Redis Labs
 
PPTX
RedisConf18 - My Other Car is a Redis Cluster
Redis Labs
 
PPTX
In Flux Limiting for a multi-tenant logging service
DataWorks Summit/Hadoop Summit
 
PPTX
RedisConf18 - Re-architecting Redis-on-Flash with Intel 3DX Point™ Memory
Redis Labs
 
PPTX
Feedback on Big Compute & HPC on Windows Azure
Antoine Poliakov
 
PPTX
Fraud Detection Architecture
Gwen (Chen) Shapira
 
PDF
How Yelp Leapt to Microservices with More than a Message Queue
confluent
 
PPTX
Webinar : Nouveautés de MongoDB 3.2
MongoDB
 
PPTX
Tracking Crime as It Occurs with Apache Phoenix, Apache HBase and Apache NiFi
DataWorks Summit
 
PDF
Redis Tames The Caching Herd: Jon Hyman
Redis Labs
 
PDF
Event driven architectures with Kinesis
Mark Harrison
 
PPTX
Intro to Apache Kafka
Jason Hubbard
 
PPTX
Redis Streams for Event-Driven Microservices
Redis Labs
 
PPTX
PlayStation and Searchable Cassandra Without Solr (Dustin Pham & Alexander Fi...
DataStax
 
PPTX
Microservices in the Apache Kafka Ecosystem
confluent
 
PDF
Securing Databases with Dynamic Credentials and HashiCorp Vault
Mitchell Pronschinske
 
PPTX
Kafka Security
DataWorks Summit/Hadoop Summit
 
PDF
Stream Me Up, Scotty: Transitioning to the Cloud Using a Streaming Data Platform
confluent
 
PDF
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Big Data Spain
 
PPTX
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Redis Labs
 
RedisConf18 - Serving Automated Home Valuation with Redis & Kafka
Redis Labs
 
RedisConf18 - My Other Car is a Redis Cluster
Redis Labs
 
In Flux Limiting for a multi-tenant logging service
DataWorks Summit/Hadoop Summit
 
RedisConf18 - Re-architecting Redis-on-Flash with Intel 3DX Point™ Memory
Redis Labs
 
Feedback on Big Compute & HPC on Windows Azure
Antoine Poliakov
 
Fraud Detection Architecture
Gwen (Chen) Shapira
 
How Yelp Leapt to Microservices with More than a Message Queue
confluent
 
Webinar : Nouveautés de MongoDB 3.2
MongoDB
 
Tracking Crime as It Occurs with Apache Phoenix, Apache HBase and Apache NiFi
DataWorks Summit
 
Redis Tames The Caching Herd: Jon Hyman
Redis Labs
 
Event driven architectures with Kinesis
Mark Harrison
 
Intro to Apache Kafka
Jason Hubbard
 
Redis Streams for Event-Driven Microservices
Redis Labs
 
PlayStation and Searchable Cassandra Without Solr (Dustin Pham & Alexander Fi...
DataStax
 
Microservices in the Apache Kafka Ecosystem
confluent
 
Securing Databases with Dynamic Credentials and HashiCorp Vault
Mitchell Pronschinske
 
Stream Me Up, Scotty: Transitioning to the Cloud Using a Streaming Data Platform
confluent
 
Keeping your Enterprise’s Big Data Secure by Owen O’Malley at Big Data Spain ...
Big Data Spain
 
Solving Complex Scaling Problems by Prashant Kumar and Abhishek Jain of Myntr...
Redis Labs
 

Similar to RedisConf18 - Scalable Microservices with Event Sourcing and Redis (20)

PPTX
Microservices & Streaming Data
Leon Mergen
 
PDF
7 reasons-why-es-cqrs
Hugh McKee
 
PDF
Redis and Kafka - Advanced Microservices Design Patterns Simplified
Allen Terleto
 
PDF
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
HostedbyConfluent
 
PDF
7 Reasons why your microservices should use Event Sourcing & CQRS
Hugh McKee
 
PPTX
Managing Data at Scale - Microservices and Events
Randy Shoup
 
PDF
The Fastest Way to Redis on Pivotal Cloud Foundry
VMware Tanzu
 
PDF
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Chris Richardson
 
PDF
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Chris Richardson
 
PDF
Developing event-driven microservices with event sourcing and CQRS (london Ja...
Chris Richardson
 
PPTX
Eda on the azure services platform
Yves Goeleven
 
PDF
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
Docker, Inc.
 
PDF
Microservices + Events + Docker = A Perfect Trio (dockercon)
Chris Richardson
 
PPTX
Patterns and practices for real-world event-driven microservices
Rachel Reese
 
PPTX
Patterns and practices for real-world event-driven microservices by Rachel Re...
Codemotion Dubai
 
PPTX
Microservices Architecture Part 2 Event Sourcing and Saga
Araf Karsh Hamid
 
PPTX
Azure Messaging with Azure Functions
Josh Carlisle
 
PDF
CQRS + Event Sourcing
Mike Bild
 
PDF
Events to the rescue: solving distributed data problems in a microservice arc...
Chris Richardson
 
PDF
Whitepaper : Event Driven Micro Services
Newt Global Consulting LLC
 
Microservices & Streaming Data
Leon Mergen
 
7 reasons-why-es-cqrs
Hugh McKee
 
Redis and Kafka - Advanced Microservices Design Patterns Simplified
Allen Terleto
 
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
HostedbyConfluent
 
7 Reasons why your microservices should use Event Sourcing & CQRS
Hugh McKee
 
Managing Data at Scale - Microservices and Events
Randy Shoup
 
The Fastest Way to Redis on Pivotal Cloud Foundry
VMware Tanzu
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Chris Richardson
 
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Chris Richardson
 
Developing event-driven microservices with event sourcing and CQRS (london Ja...
Chris Richardson
 
Eda on the azure services platform
Yves Goeleven
 
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
Docker, Inc.
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Chris Richardson
 
Patterns and practices for real-world event-driven microservices
Rachel Reese
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Codemotion Dubai
 
Microservices Architecture Part 2 Event Sourcing and Saga
Araf Karsh Hamid
 
Azure Messaging with Azure Functions
Josh Carlisle
 
CQRS + Event Sourcing
Mike Bild
 
Events to the rescue: solving distributed data problems in a microservice arc...
Chris Richardson
 
Whitepaper : Event Driven Micro Services
Newt Global Consulting LLC
 
Ad

More from Redis Labs (20)

PPTX
Redis Day Bangalore 2020 - Session state caching with redis
Redis Labs
 
PPTX
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Redis Labs
 
PPTX
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
Redis Labs
 
PPTX
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
Redis Labs
 
PPTX
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Redis Labs
 
PPTX
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis Labs
 
PPTX
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Redis Labs
 
PPTX
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Redis Labs
 
PPTX
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Redis Labs
 
PPTX
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
Redis Labs
 
PPTX
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Redis Labs
 
PPTX
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Redis Labs
 
PPTX
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Redis Labs
 
PPTX
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
PPTX
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
PPTX
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
PPTX
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
Redis Labs
 
PPTX
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Redis Labs
 
PDF
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Redis Labs
 
PPTX
Redis as a High Scale Swiss Army Knife by Rahul Dagar and Abhishek Gupta of G...
Redis Labs
 
Redis Day Bangalore 2020 - Session state caching with redis
Redis Labs
 
Protecting Your API with Redis by Jane Paek - Redis Day Seattle 2020
Redis Labs
 
The Happy Marriage of Redis and Protobuf by Scott Haines of Twilio - Redis Da...
Redis Labs
 
SQL, Redis and Kubernetes by Paul Stanton of Windocks - Redis Day Seattle 2020
Redis Labs
 
Rust and Redis - Solving Problems for Kubernetes by Ravi Jagannathan of VMwar...
Redis Labs
 
Redis for Data Science and Engineering by Dmitry Polyakovsky of Oracle
Redis Labs
 
Practical Use Cases for ACLs in Redis 6 by Jamie Scott - Redis Day Seattle 2020
Redis Labs
 
Moving Beyond Cache by Yiftach Shoolman Redis Labs - Redis Day Seattle 2020
Redis Labs
 
Leveraging Redis for System Monitoring by Adam McCormick of SBG - Redis Day S...
Redis Labs
 
JSON in Redis - When to use RedisJSON by Jay Won of Coupang - Redis Day Seatt...
Redis Labs
 
Highly Available Persistent Session Management Service by Mohamed Elmergawi o...
Redis Labs
 
Anatomy of a Redis Command by Madelyn Olson of Amazon Web Services - Redis Da...
Redis Labs
 
Building a Multi-dimensional Analytics Engine with RedisGraph by Matthew Goos...
Redis Labs
 
RediSearch 1.6 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
RedisGraph 2.0 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
RedisTimeSeries 1.2 by Pieter Cailliau - Redis Day Bangalore 2020
Redis Labs
 
RedisAI 0.9 by Sherin Thomas of Tensorwerk - Redis Day Bangalore 2020
Redis Labs
 
Rate-Limiting 30 Million requests by Vijay Lakshminarayanan and Girish Koundi...
Redis Labs
 
Three Pillars of Observability by Rajalakshmi Raji Srinivasan of Site24x7 Zoh...
Redis Labs
 
Redis as a High Scale Swiss Army Knife by Rahul Dagar and Abhishek Gupta of G...
Redis Labs
 
Ad

Recently uploaded (20)

PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

RedisConf18 - Scalable Microservices with Event Sourcing and Redis

Editor's Notes

  • #3: While adopting a microservices, or service based architecture comes with a lot of benefits including ease of deployment, resiliency, reliability, and performance, it also comes with it’s own set of challenges that we don’t have with a monolithic application. Today I will talk about how we can address some of those challenges by making our services event-driven with the help of Redis. I’ll talk about some useful patterns for implementing event-driven services with Redis, and then do a brief walkthrough of a demo application that shows these patterns in practice.
  • #4: One of the main issues we face with microservices is how do services communicate with one another. Often, communication is implemented with HTTP calls between services. So, for example… Three main problems: Services are tightly coupled, The Order Service must know about the Customer Service and it’s API; If Customer service is down, we are forced to either have inconsistent data or to implement distributed transactions and give the user an error; Performance issues, UI must wait for all of the various API calls to complete successfully.
  • #6: Decouples services, now Order Service doesn’t need to know anything about Customer Service or Inventory Service Writes are now inherently atomic as they only need to write to the message queue and we don’t need to worry about distributed transactions. The system can maintain consistency and availability although it is now “eventually consistent”. If Customer service goes down, it can still process it’s events waiting in the queue once it comes back up. All updates to other services are now asynchronous. The client does not have to wait for multiple calls to multiple services. However, eventual consistency must be kept in mind here too. Updates to data in Customer Service or Inventory Service won’t be immediate.
  • #8: Redis pub/sub is very basi. It does not persist events, so if there is no subscriber at the time the event is written, the data will be lost. Therefore, we have to implement a more reliable mechanism to prevent data loss. 1. An event subscriber registers itself in a Subscribers List in Redis. 2. When an event is published, event data is written to a Published List for each subscriber and a Redis message is published in an atomic operation. The event does not contain any data itself — it is simply notifying subscribers that there is event data waiting to be processed in the Published List. If a subscriber goes down, data will continue to be written to its Published List and can be picked up and processed by the subscriber once it comes back up. 3. When a subscriber receives an event notification, it pops the event data from the Published List and pushes it to another Processing List in an atomic operation using the RPOPLPUSH command. This makes it possible to have multiple instances of a subscriber running, but ensures that only one of them will actually pick up the event data and process it. All instances will receive the event notification, but only one of them can pick up the event data and process it. 4. Once processing is complete, event data is removed from the Processing List. If an error is encountered during processing, data remains in the Processing List and processing can be retried at a later time.
  • #9: ““Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects. This can simplify tasks in complex domains, by avoiding the need to synchronize the data model and the business domain, while improving performance, scalability, and responsiveness. It can also provide consistency for transactional data, and maintain full audit trails and history that can enable compensating actions.” The fundamental primitive in the EventStore is a domain object or Aggregate. Going back to the example above this would be something like an Order. The state of the Aggregate object is stored as a series of events. For example, there may be something like OrderCreated, QuantityChanged, OrderDeleted, etc.
  • #10: Within the event store, data is stored using a combination of data types offered by Redis: A Redis List stores the stream of events for an Aggregate. Redis Hashes store the actual data associated with each event. Each Aggregate recieves a unique Aggregate ID in the form of a GUID. Each Aggregate then has a Commit List associated with it that is keyed off of the unique Aggregate ID. Each event that is stored for a particular Aggregate recieves a unique Commit ID. The Commit List for the Aggregate simply stores all of the Commit IDs associated with the Aggregate in the order that they were created. A Redis List is used for this because it maintains the order of the values as they are inserted and adding values to the end of a list is very fast as it is an O(1) operation. For each Commit ID within the Commit List, there is a corresponding entry in a Redis Hash that uses the Commit ID as the key and stores the JSON formatted event data as the value. Retrieving a single entry for a Hash is also a fast O(1) operation. In order to retrieve all events for an Aggregate, the entire Commit List can be retrieved using the Redis LRANGE command. The list can then be iterated through and an HGET command issued to retrieve the data for each event. We use a CRC32 hash of the Commit ID and a modulo operation to partition the event data into multiple Redis Hashes.
  • #11: CQRS means "Command-query responsibility segregation". We segregate the responsibility between commands (write requests) and queries (read requests). The write requests and the read requests are handled by different objects. This makes sense with Event Sourcing and event driven systems in general because all of our commands are publishing events and all of our queries are run against a “read model” that is written to by our event subscribers.