SlideShare a Scribd company logo
1 of 56
Managing Data at Scale
Microservices and Events
Randy Shoup
@randyshoup
linkedin.com/in/randyshoup
Evolution to
Microservices
• eBay
• 5th generation today
• Monolithic Perl  Monolithic C++  Java  microservices
• Twitter
• 3rd generation today
• Monolithic Rails  JS / Rails / Scala  microservices
• Amazon
• Nth generation today
• Monolithic Perl / C++  Java / Scala  microservices
@randyshoup linkedin.com/in/randyshoup
No one starts with microservices
…
Past a certain scale, everyone
ends up with microservices
First Law of Distributed Object
Design:
Don’t distribute your objects!
-- Martin Fowler
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
Microservices
• Single-purpose
• Simple, well-defined interface
• Modular and independent
• Isolated persistence (!)
A
C D E
B
Extracting
Microservices
• Problem: Monolithic shared DB
• Clients
• Shipments
• Items
• Styles, SKUs
• Warehouses
• etc.
stitchfix.com Styling app Warehouse app Merch app
CS app Logistics app Payments service Profile service
Extracting
Microservices
• Decouple applications / services from shared DB
• Clients
• Shipments
• Items
• Styles, SKUs
• Warehouses
• etc.
stitchfix.com Styling app Warehouse app Merch app
CS app Logistics app Payments service Profile service
Extracting
Microservices
• Decouple applications / services from shared DB
Styling app Warehouse app
core_item
core_sku
core_client
Extracting
Microservices
• Step 1: Create a service
Styling app Warehouse app
core_item
core_sku
core_client
client-service
Extracting
Microservices
• Step 2: Applications use the service
Styling app Warehouse app
core_item
core_sku
core_client
client-service
Extracting
Microservices
• Step 3: Move data to private database
Styling app Warehouse app
core_item
core_sku
client-service
core_client
Extracting
Microservices
• Step 4: Rinse and Repeat
Styling app Warehouse app
core_sku
client-service
core_client
item-service
core_item
Extracting
Microservices
• Step 4: Rinse and Repeat
Styling app Warehouse app
client-service
core_client
item-service
core_item
style-service
core_sku
Extracting
Microservices
• Step 4: Rinse and Repeat
Styling app Warehouse app
client-service
core_client
item-service
core_item
style-service
core_sku
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
o Two Architectural Tools
o Shared Data
o Joins
o Transactions
• Challenges of Event-Driven Systems
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
o Two Architectural Tools
o Shared Data
o Joins
o Transactions
• Challenges of Event-Driven Systems
Service as
System of Record
• Single System of Record
o Every piece of data is owned by a single service
o That service is the canonical system of record for that data
• Every other copy is a read-only, non-authoritative
cache
@randyshoup linkedin.com/in/randyshoup
customer-service
styling-service
customer-search
billing-service
Events as
First-Class Construct
• “A significant change in state”
o Statement that some interesting thing occurred
• Traditional 3-tier system
o Presentation  interface / interaction
o Application  stateless business logic
o Persistence  database
• Fourth fundamental building block
o State changes  events
o 0 | 1 | N consumers subscribe to the event, typically asynchronously
@randyshoup linkedin.com/in/randyshoup
Microservices
and Events
• Events are a first-class part of a service interface
• A service interface includes
o Synchronous request-response (REST, gRPC, etc)
o Events the service produces
o Events the service consumes
o Bulk reads and writes (ETL)
• The interface includes any mechanism for getting data in
or out of the service (!)
@randyshoup linkedin.com/in/randyshoup
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
o Two Architectural Tools
o Shared Data
o Joins
o Transactions
• Challenges of Event-Driven Systems
Data in Microservices:
Shared Data
• Monolithic database makes it easy to leverage shared
data
• Where does shared data go in a microservices world?
@randyshoup linkedin.com/in/randyshoup
Data in Microservices:
Shared Data
Option 1: Synchronous Lookup
o Customer service owns customer data
o Fulfillment service calls customer service in real time
fulfillment-service
customer-service
@randyshoup linkedin.com/in/randyshoup
Data in Microservices:
Shared Data
Option 2: Async event + local cache
o Customer service owns customer data
o Customer service sends address-updated event when customer address
changes
o Fulfillment service caches current customer address
fulfillment-servicecustomer-service
@randyshoup linkedin.com/in/randyshoup
Data in Microservices:
Shared Data
Option 3: Shared metadata library
o Read-only metadata, basically immutable
o E.g., size schemas, colors, fabrics, US States, etc.
receiving-serviceitem-service
style-service
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
o Two Architectural Tools
o Shared Data
o Joins
o Transactions
• Challenges of Event-Driven Systems
Data in Microservices:
Joins
• Monolithic database makes it easy to join tables
• Splitting the data across microservices makes joins very
hard
@randyshoup linkedin.com/in/randyshoup
SELECT FROM A INNER JOIN B ON …
Data in Microservices:
Joins
Option 1: Join in Client Application
o Get a single customer from customer-service
o Query matching orders for that customer from order-service
Customers
Orders
order-history-page
customer-service order-service
Data in Microservices:
Joins
Option 2: Service that “Materializes the View”
o Listen to events from item-service, events from order-service
o Maintain denormalized join of items and orders together in local storage
Items Order Feedback
item-feedback-service
item-service
order-feedback-service
Data in Microservices:
Joins
• Many common systems do this
o “Materialized view” in database systems
o Most NoSQL systems
o Search engines
o Analytic systems
@randyshoup linkedin.com/in/randyshoup
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
o Two Architectural Tools
o Shared Data
o Joins
o Transactions
• Challenges of Event-Driven Systems
Data in Microservices:
Transactions
• Monolithic database makes transactions across multiple
entities easy
• Splitting data across services makes transactions very
hard
@randyshoup linkedin.com/in/randyshoup
BEGIN; INSERT INTO A …; UPDATE B...; COMMIT;
“In general, application
developers simply do not
implement large scalable
applications assuming
distributed transactions.”
-- Pat Helland
Life After Distributed Transactions: An Apostate’s Opinion, 2007
“Grownups don’t use
distributed transactions”
-- Pat Helland
Data in Microservices:
Workflows and Sagas
• Transaction  Saga
o Model the transaction as a state machine of atomic events
• Reimplement as a workflow
• Roll back by applying compensating operations in
reverse
A B C
A B C
@randyshoup linkedin.com/in/randyshoup
Data in Microservices:
Workflows and Sagas
• Many common systems do this
o Payment processing
o Expense approval
o Travel
o Any multi-step workflow
@randyshoup linkedin.com/in/randyshoup
Data in Microservices:
Workflows and Sagas
• Simple event-driven processing
o Very lightweight logic
o Stateless
o Triggered by an event
•  Consider Function-as-a-Service (“Serverless”)
A B C
A B C
@randyshoup linkedin.com/in/randyshoup
ƛ ƛ ƛ
ƛ ƛ ƛ
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
o Event Duplication
o Event Ordering
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
o Event Duplication
o Event Ordering
Event
Duplication
• Problem: The same event will be delivered more than
once
o Network issues
o Redelivery
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-1
• Event-2
• Event-2
• Event-3
Event
Duplication
• The consumer must process an event correctly
regardless of how many times it receives it
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-1
• Event-2
• Event-2
• Event-3
• Event-1
• Event-2
• Event-3
Event Duplication:
(A) Exactly Once Delivery
Message bus buffers messages
o Message bus remembers events it has delivered, identified by message id
o Only deliver event if not yet delivered
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
• Event-1 [1]
• Event-2 [2]
• Event-2 [2]
• Event-3 [3]
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
Event Duplication:
(B) Idempotent Processing
Option 1: Idempotency key
o Remember previously processed events, identified by idempotency key
o Before processing, check whether you have processed it already
o E.g., counter
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1 [aaa]
• Event-2 [bbb]
• Event-3 [ccc]
• Event-1 [aaa]
• Event-2 [bbb]
• Event-2 [bbb]
• Event-3 [ccc]
• Event-1
• Event-2
• <nothing>
• Event-3
aaa
aaa,bbb
aaa,bbb
aaa,bbb,ccc
Event Duplication:
(B) Idempotent Processing
Option 2: Processing is inherently idempotent
o Simply do the processing N times for N events
o E.g., “set X to 10”, UPSERT
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-1
• Event-2
• Event-2
• Event-3
• Set x:=1
• Set x:=2
• Set x:=2
• Set x:=3
Event Duplication:
(B) Idempotent Processing
Option 3: Conflict-free Replicated Datatypes (CRDTs)
o Achieve agreement without explicit coordination
o Custom data structures, composable processing steps
o Many implementations, but still an area of active research
Common techniques
o Remember what you saw (request id, idempotency key)
o Remember that an item was deleted (“tombstone”)
(Do *NOT* roll your own from first principles)
@randyshoup linkedin.com/in/randyshoup
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
o Event Duplication
o Event Ordering
Event
Ordering
• Problem: Events will arrive out of order
o Network issues
o Processing time
o Redelivery
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-2
• Event-1
• Event-3
Event
Ordering
• The consumer must process events correctly regardless
of the order in which they arrive
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-2
• Event-1
• Event-3
• Event-1
• Event-2
• Event-3
Event Ordering:
(A) Impose Order
Option 1: Sequence + Reorder in the message bus
o Sequence number at the producer
o Message bus queues messages, waits for gaps
o Bus sends to consumer in order
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
• Event-2 [2]
• Event-1 [1]
• Event-3 [3]
Event Ordering:
(A) Impose Order
Option 2: Sequence + Reorder in the consumer
o Sequence number / timestamp at the producer
o Consumer reorders before processing
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
• Event-2 [2]
• Event-1 [1]
• Event-3 [3]
• Event-1 [1]
• Event-2 [2]
• Event-3 [3]
Event Ordering:
(B) Order-Independence
Option 1: Order-independent semantics
o E.g., count number of events
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-2
• Event-1
• Event-3
• +1
• +1
• +1
Event Ordering:
(B) Order-Independence
Option 2: Notification + Read-back
o Event is a notification: object id + type of change
o Consumer “reads back” to the source service to get current state
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-2
• Event-1
• Event-3
• State = 2
• State = 2
• State = 3
Event Ordering:
(B) Order-Independence
Option 3: Event Sourcing
o Store all events in a log
o Process / interpret later
@randyshoup linkedin.com/in/randyshoup
Producer ConsumerTransport
• Event-1
• Event-2
• Event-3
• Event-2
• Event-1
• Event-3
Event-2
Event-1
Event-3
• Event-1
• Event-2
• Event-3
Managing Data
at Scale
• Migrating to Microservices
• Challenges of Data in Microservices
• Challenges of Event-Driven Systems
¡Gracias!
@randyshoup
linkedin.com/in/randyshoup
medium.com/@randyshoup

More Related Content

What's hot

What's hot (20)

Learning from Learnings: Anatomy of Three Incidents
Learning from Learnings: Anatomy of Three IncidentsLearning from Learnings: Anatomy of Three Incidents
Learning from Learnings: Anatomy of Three Incidents
 
Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015Service Architectures At Scale - QCon London 2015
Service Architectures At Scale - QCon London 2015
 
Art of the Possible - Serverless Conference NYC 2017
Art of the Possible - Serverless Conference NYC 2017 Art of the Possible - Serverless Conference NYC 2017
Art of the Possible - Serverless Conference NYC 2017
 
Being Elastic -- Evolving Programming for the Cloud
Being Elastic -- Evolving Programming for the CloudBeing Elastic -- Evolving Programming for the Cloud
Being Elastic -- Evolving Programming for the Cloud
 
Managing a Microservices Development Team (And advanced Microservice concerns)
Managing a Microservices Development Team (And advanced Microservice concerns)Managing a Microservices Development Team (And advanced Microservice concerns)
Managing a Microservices Development Team (And advanced Microservice concerns)
 
Api fundamentals
Api fundamentalsApi fundamentals
Api fundamentals
 
Microservices: The Organizational and People Impact
Microservices: The Organizational and People ImpactMicroservices: The Organizational and People Impact
Microservices: The Organizational and People Impact
 
You build it - Cyber Chicago Keynote
You build it -  Cyber Chicago KeynoteYou build it -  Cyber Chicago Keynote
You build it - Cyber Chicago Keynote
 
Tech view on Regulatory Compliance
Tech view on Regulatory ComplianceTech view on Regulatory Compliance
Tech view on Regulatory Compliance
 
Content Engineering and The Internet of “Smart” Things
Content Engineering and The Internet of “Smart” ThingsContent Engineering and The Internet of “Smart” Things
Content Engineering and The Internet of “Smart” Things
 
DataEngConf SF16 - Methods for Content Relevance at LinkedIn
DataEngConf SF16 - Methods for Content Relevance at LinkedInDataEngConf SF16 - Methods for Content Relevance at LinkedIn
DataEngConf SF16 - Methods for Content Relevance at LinkedIn
 
DevSecOps - London Gathering : June 2018
DevSecOps - London Gathering : June 2018DevSecOps - London Gathering : June 2018
DevSecOps - London Gathering : June 2018
 
Galichet XML Workflow Brief History NISO
Galichet XML Workflow Brief History NISOGalichet XML Workflow Brief History NISO
Galichet XML Workflow Brief History NISO
 
Galichet XML for Standards Publishers October 9
Galichet XML for Standards Publishers October 9Galichet XML for Standards Publishers October 9
Galichet XML for Standards Publishers October 9
 
Operations for databases: the agile/devops journey
Operations for databases: the agile/devops journeyOperations for databases: the agile/devops journey
Operations for databases: the agile/devops journey
 
Workflowvs vs Flow 365 Saturday Amsterdam
Workflowvs vs Flow 365 Saturday AmsterdamWorkflowvs vs Flow 365 Saturday Amsterdam
Workflowvs vs Flow 365 Saturday Amsterdam
 
West Putting Structured Documents to Work
West Putting Structured Documents to WorkWest Putting Structured Documents to Work
West Putting Structured Documents to Work
 
Wheeler West NISO STS An XML Standard for Standards
Wheeler West NISO STS An XML Standard for StandardsWheeler West NISO STS An XML Standard for Standards
Wheeler West NISO STS An XML Standard for Standards
 
Taking Over & Managing Large Messy Systems
Taking Over & Managing Large Messy SystemsTaking Over & Managing Large Messy Systems
Taking Over & Managing Large Messy Systems
 
Database Source Control: Migrations vs State
Database Source Control: Migrations vs StateDatabase Source Control: Migrations vs State
Database Source Control: Migrations vs State
 

Similar to Managing Data at Scale - Microservices and Events

Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Lightbend
 
MongoDB Breakfast Milan - Mainframe Offloading Strategies
MongoDB Breakfast Milan -  Mainframe Offloading StrategiesMongoDB Breakfast Milan -  Mainframe Offloading Strategies
MongoDB Breakfast Milan - Mainframe Offloading Strategies
MongoDB
 

Similar to Managing Data at Scale - Microservices and Events (20)

Kafka Summit SF 2017 - Keynote - Managing Data at Scale: The Unreasonable Eff...
Kafka Summit SF 2017 - Keynote - Managing Data at Scale: The Unreasonable Eff...Kafka Summit SF 2017 - Keynote - Managing Data at Scale: The Unreasonable Eff...
Kafka Summit SF 2017 - Keynote - Managing Data at Scale: The Unreasonable Eff...
 
Assessing New Databases– Translytical Use Cases
Assessing New Databases– Translytical Use CasesAssessing New Databases– Translytical Use Cases
Assessing New Databases– Translytical Use Cases
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Patterns of Distributed Application Design
Patterns of Distributed Application DesignPatterns of Distributed Application Design
Patterns of Distributed Application Design
 
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of SimplicityLarge Scale Architecture -- The Unreasonable Effectiveness of Simplicity
Large Scale Architecture -- The Unreasonable Effectiveness of Simplicity
 
Big data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on AzureBig data streaming with Apache Spark on Azure
Big data streaming with Apache Spark on Azure
 
Microservice - Data Management
Microservice - Data ManagementMicroservice - Data Management
Microservice - Data Management
 
The Evolution of Big Data Pipelines at Intuit
The Evolution of Big Data Pipelines at Intuit The Evolution of Big Data Pipelines at Intuit
The Evolution of Big Data Pipelines at Intuit
 
Webinar: How to Drive Business Value in Financial Services with MongoDB
Webinar: How to Drive Business Value in Financial Services with MongoDBWebinar: How to Drive Business Value in Financial Services with MongoDB
Webinar: How to Drive Business Value in Financial Services with MongoDB
 
When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...
 
Enabling Telco to Build and Run Modern Applications
Enabling Telco to Build and Run Modern Applications Enabling Telco to Build and Run Modern Applications
Enabling Telco to Build and Run Modern Applications
 
Systematic Migration of Monolith to Microservices
Systematic Migration of Monolith to MicroservicesSystematic Migration of Monolith to Microservices
Systematic Migration of Monolith to Microservices
 
Webinar: Achieving Customer Centricity and High Margins in Financial Services...
Webinar: Achieving Customer Centricity and High Margins in Financial Services...Webinar: Achieving Customer Centricity and High Margins in Financial Services...
Webinar: Achieving Customer Centricity and High Margins in Financial Services...
 
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
Building Streaming And Fast Data Applications With Spark, Mesos, Akka, Cassan...
 
MongoDB Breakfast Milan - Mainframe Offloading Strategies
MongoDB Breakfast Milan -  Mainframe Offloading StrategiesMongoDB Breakfast Milan -  Mainframe Offloading Strategies
MongoDB Breakfast Milan - Mainframe Offloading Strategies
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
 
Hadoop Summit 2016 - Evolution of Big Data Pipelines At Intuit
Hadoop Summit 2016 - Evolution of Big Data Pipelines At IntuitHadoop Summit 2016 - Evolution of Big Data Pipelines At Intuit
Hadoop Summit 2016 - Evolution of Big Data Pipelines At Intuit
 
Moving To MicroServices
Moving To MicroServicesMoving To MicroServices
Moving To MicroServices
 
Spark meetup stream processing use cases
Spark meetup   stream processing use casesSpark meetup   stream processing use cases
Spark meetup stream processing use cases
 
Neo4j GraphTalks - Introduction to GraphDatabases and Neo4j
Neo4j GraphTalks - Introduction to GraphDatabases and Neo4jNeo4j GraphTalks - Introduction to GraphDatabases and Neo4j
Neo4j GraphTalks - Introduction to GraphDatabases and Neo4j
 

More from Randy Shoup

An Agile Approach to Machine Learning
An Agile Approach to Machine LearningAn Agile Approach to Machine Learning
An Agile Approach to Machine Learning
Randy Shoup
 
DevOps - It's About How We Work
DevOps - It's About How We WorkDevOps - It's About How We Work
DevOps - It's About How We Work
Randy Shoup
 
Ten Lessons of the DevOps Transition
Ten Lessons of the DevOps TransitionTen Lessons of the DevOps Transition
Ten Lessons of the DevOps Transition
Randy Shoup
 

More from Randy Shoup (19)

Anatomy of Three Incidents -- Commonalities and Lessons
Anatomy of Three Incidents -- Commonalities and LessonsAnatomy of Three Incidents -- Commonalities and Lessons
Anatomy of Three Incidents -- Commonalities and Lessons
 
One Terrible Day at Google, and How It Made Us Better
One Terrible Day at Google, and How It Made Us BetterOne Terrible Day at Google, and How It Made Us Better
One Terrible Day at Google, and How It Made Us Better
 
Minimal Viable Architecture - Silicon Slopes 2020
Minimal Viable Architecture - Silicon Slopes 2020Minimal Viable Architecture - Silicon Slopes 2020
Minimal Viable Architecture - Silicon Slopes 2020
 
An Agile Approach to Machine Learning
An Agile Approach to Machine LearningAn Agile Approach to Machine Learning
An Agile Approach to Machine Learning
 
Moving Fast at Scale
Moving Fast at ScaleMoving Fast at Scale
Moving Fast at Scale
 
Breaking Codes, Designing Jets, and Building Teams
Breaking Codes, Designing Jets, and Building TeamsBreaking Codes, Designing Jets, and Building Teams
Breaking Codes, Designing Jets, and Building Teams
 
Moving Fast At Scale
Moving Fast At ScaleMoving Fast At Scale
Moving Fast At Scale
 
DevOps - It's About How We Work
DevOps - It's About How We WorkDevOps - It's About How We Work
DevOps - It's About How We Work
 
Ten Lessons of the DevOps Transition
Ten Lessons of the DevOps TransitionTen Lessons of the DevOps Transition
Ten Lessons of the DevOps Transition
 
Pragmatic Microservices
Pragmatic MicroservicesPragmatic Microservices
Pragmatic Microservices
 
A CTO's Guide to Scaling Organizations
A CTO's Guide to Scaling OrganizationsA CTO's Guide to Scaling Organizations
A CTO's Guide to Scaling Organizations
 
From the Monolith to Microservices - CraftConf 2015
From the Monolith to Microservices - CraftConf 2015From the Monolith to Microservices - CraftConf 2015
From the Monolith to Microservices - CraftConf 2015
 
Concurrency at Scale: Evolution to Micro-Services
Concurrency at Scale:  Evolution to Micro-ServicesConcurrency at Scale:  Evolution to Micro-Services
Concurrency at Scale: Evolution to Micro-Services
 
Minimum Viable Architecture -- Good Enough is Good Enough in a Startup
Minimum Viable Architecture -- Good Enough is Good Enough in a StartupMinimum Viable Architecture -- Good Enough is Good Enough in a Startup
Minimum Viable Architecture -- Good Enough is Good Enough in a Startup
 
Why Enterprises Are Embracing the Cloud
Why Enterprises Are Embracing the CloudWhy Enterprises Are Embracing the Cloud
Why Enterprises Are Embracing the Cloud
 
DevOpsDays Silicon Valley 2014 - The Game of Operations
DevOpsDays Silicon Valley 2014 - The Game of OperationsDevOpsDays Silicon Valley 2014 - The Game of Operations
DevOpsDays Silicon Valley 2014 - The Game of Operations
 
QCon New York 2014 - Scalable, Reliable Analytics Infrastructure at KIXEYE
QCon New York 2014 - Scalable, Reliable Analytics Infrastructure at KIXEYEQCon New York 2014 - Scalable, Reliable Analytics Infrastructure at KIXEYE
QCon New York 2014 - Scalable, Reliable Analytics Infrastructure at KIXEYE
 
QCon Tokyo 2014 - Virtuous Cycles of Velocity: What I Learned About Going Fas...
QCon Tokyo 2014 - Virtuous Cycles of Velocity: What I Learned About Going Fas...QCon Tokyo 2014 - Virtuous Cycles of Velocity: What I Learned About Going Fas...
QCon Tokyo 2014 - Virtuous Cycles of Velocity: What I Learned About Going Fas...
 
The Importance of Culture: Building and Sustaining Effective Engineering Org...
The Importance of Culture:  Building and Sustaining Effective Engineering Org...The Importance of Culture:  Building and Sustaining Effective Engineering Org...
The Importance of Culture: Building and Sustaining Effective Engineering Org...
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

Managing Data at Scale - Microservices and Events

  • 1. Managing Data at Scale Microservices and Events Randy Shoup @randyshoup linkedin.com/in/randyshoup
  • 2. Evolution to Microservices • eBay • 5th generation today • Monolithic Perl  Monolithic C++  Java  microservices • Twitter • 3rd generation today • Monolithic Rails  JS / Rails / Scala  microservices • Amazon • Nth generation today • Monolithic Perl / C++  Java / Scala  microservices @randyshoup linkedin.com/in/randyshoup
  • 3. No one starts with microservices … Past a certain scale, everyone ends up with microservices
  • 4. First Law of Distributed Object Design: Don’t distribute your objects! -- Martin Fowler
  • 5. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems
  • 6. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems
  • 7. Microservices • Single-purpose • Simple, well-defined interface • Modular and independent • Isolated persistence (!) A C D E B
  • 8. Extracting Microservices • Problem: Monolithic shared DB • Clients • Shipments • Items • Styles, SKUs • Warehouses • etc. stitchfix.com Styling app Warehouse app Merch app CS app Logistics app Payments service Profile service
  • 9. Extracting Microservices • Decouple applications / services from shared DB • Clients • Shipments • Items • Styles, SKUs • Warehouses • etc. stitchfix.com Styling app Warehouse app Merch app CS app Logistics app Payments service Profile service
  • 10. Extracting Microservices • Decouple applications / services from shared DB Styling app Warehouse app core_item core_sku core_client
  • 11. Extracting Microservices • Step 1: Create a service Styling app Warehouse app core_item core_sku core_client client-service
  • 12. Extracting Microservices • Step 2: Applications use the service Styling app Warehouse app core_item core_sku core_client client-service
  • 13. Extracting Microservices • Step 3: Move data to private database Styling app Warehouse app core_item core_sku client-service core_client
  • 14. Extracting Microservices • Step 4: Rinse and Repeat Styling app Warehouse app core_sku client-service core_client item-service core_item
  • 15. Extracting Microservices • Step 4: Rinse and Repeat Styling app Warehouse app client-service core_client item-service core_item style-service core_sku
  • 16. Extracting Microservices • Step 4: Rinse and Repeat Styling app Warehouse app client-service core_client item-service core_item style-service core_sku
  • 17. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices o Two Architectural Tools o Shared Data o Joins o Transactions • Challenges of Event-Driven Systems
  • 18. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices o Two Architectural Tools o Shared Data o Joins o Transactions • Challenges of Event-Driven Systems
  • 19. Service as System of Record • Single System of Record o Every piece of data is owned by a single service o That service is the canonical system of record for that data • Every other copy is a read-only, non-authoritative cache @randyshoup linkedin.com/in/randyshoup customer-service styling-service customer-search billing-service
  • 20. Events as First-Class Construct • “A significant change in state” o Statement that some interesting thing occurred • Traditional 3-tier system o Presentation  interface / interaction o Application  stateless business logic o Persistence  database • Fourth fundamental building block o State changes  events o 0 | 1 | N consumers subscribe to the event, typically asynchronously @randyshoup linkedin.com/in/randyshoup
  • 21. Microservices and Events • Events are a first-class part of a service interface • A service interface includes o Synchronous request-response (REST, gRPC, etc) o Events the service produces o Events the service consumes o Bulk reads and writes (ETL) • The interface includes any mechanism for getting data in or out of the service (!) @randyshoup linkedin.com/in/randyshoup
  • 22. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices o Two Architectural Tools o Shared Data o Joins o Transactions • Challenges of Event-Driven Systems
  • 23. Data in Microservices: Shared Data • Monolithic database makes it easy to leverage shared data • Where does shared data go in a microservices world? @randyshoup linkedin.com/in/randyshoup
  • 24. Data in Microservices: Shared Data Option 1: Synchronous Lookup o Customer service owns customer data o Fulfillment service calls customer service in real time fulfillment-service customer-service @randyshoup linkedin.com/in/randyshoup
  • 25. Data in Microservices: Shared Data Option 2: Async event + local cache o Customer service owns customer data o Customer service sends address-updated event when customer address changes o Fulfillment service caches current customer address fulfillment-servicecustomer-service @randyshoup linkedin.com/in/randyshoup
  • 26. Data in Microservices: Shared Data Option 3: Shared metadata library o Read-only metadata, basically immutable o E.g., size schemas, colors, fabrics, US States, etc. receiving-serviceitem-service style-service
  • 27. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices o Two Architectural Tools o Shared Data o Joins o Transactions • Challenges of Event-Driven Systems
  • 28. Data in Microservices: Joins • Monolithic database makes it easy to join tables • Splitting the data across microservices makes joins very hard @randyshoup linkedin.com/in/randyshoup SELECT FROM A INNER JOIN B ON …
  • 29. Data in Microservices: Joins Option 1: Join in Client Application o Get a single customer from customer-service o Query matching orders for that customer from order-service Customers Orders order-history-page customer-service order-service
  • 30. Data in Microservices: Joins Option 2: Service that “Materializes the View” o Listen to events from item-service, events from order-service o Maintain denormalized join of items and orders together in local storage Items Order Feedback item-feedback-service item-service order-feedback-service
  • 31. Data in Microservices: Joins • Many common systems do this o “Materialized view” in database systems o Most NoSQL systems o Search engines o Analytic systems @randyshoup linkedin.com/in/randyshoup
  • 32. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices o Two Architectural Tools o Shared Data o Joins o Transactions • Challenges of Event-Driven Systems
  • 33. Data in Microservices: Transactions • Monolithic database makes transactions across multiple entities easy • Splitting data across services makes transactions very hard @randyshoup linkedin.com/in/randyshoup BEGIN; INSERT INTO A …; UPDATE B...; COMMIT;
  • 34. “In general, application developers simply do not implement large scalable applications assuming distributed transactions.” -- Pat Helland Life After Distributed Transactions: An Apostate’s Opinion, 2007
  • 35. “Grownups don’t use distributed transactions” -- Pat Helland
  • 36. Data in Microservices: Workflows and Sagas • Transaction  Saga o Model the transaction as a state machine of atomic events • Reimplement as a workflow • Roll back by applying compensating operations in reverse A B C A B C @randyshoup linkedin.com/in/randyshoup
  • 37. Data in Microservices: Workflows and Sagas • Many common systems do this o Payment processing o Expense approval o Travel o Any multi-step workflow @randyshoup linkedin.com/in/randyshoup
  • 38. Data in Microservices: Workflows and Sagas • Simple event-driven processing o Very lightweight logic o Stateless o Triggered by an event •  Consider Function-as-a-Service (“Serverless”) A B C A B C @randyshoup linkedin.com/in/randyshoup ƛ ƛ ƛ ƛ ƛ ƛ
  • 39. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems o Event Duplication o Event Ordering
  • 40. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems o Event Duplication o Event Ordering
  • 41. Event Duplication • Problem: The same event will be delivered more than once o Network issues o Redelivery @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-1 • Event-2 • Event-2 • Event-3
  • 42. Event Duplication • The consumer must process an event correctly regardless of how many times it receives it @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-1 • Event-2 • Event-2 • Event-3 • Event-1 • Event-2 • Event-3
  • 43. Event Duplication: (A) Exactly Once Delivery Message bus buffers messages o Message bus remembers events it has delivered, identified by message id o Only deliver event if not yet delivered @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-1 [1] • Event-2 [2] • Event-3 [3] • Event-1 [1] • Event-2 [2] • Event-2 [2] • Event-3 [3] • Event-1 [1] • Event-2 [2] • Event-3 [3]
  • 44. Event Duplication: (B) Idempotent Processing Option 1: Idempotency key o Remember previously processed events, identified by idempotency key o Before processing, check whether you have processed it already o E.g., counter @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 [aaa] • Event-2 [bbb] • Event-3 [ccc] • Event-1 [aaa] • Event-2 [bbb] • Event-2 [bbb] • Event-3 [ccc] • Event-1 • Event-2 • <nothing> • Event-3 aaa aaa,bbb aaa,bbb aaa,bbb,ccc
  • 45. Event Duplication: (B) Idempotent Processing Option 2: Processing is inherently idempotent o Simply do the processing N times for N events o E.g., “set X to 10”, UPSERT @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-1 • Event-2 • Event-2 • Event-3 • Set x:=1 • Set x:=2 • Set x:=2 • Set x:=3
  • 46. Event Duplication: (B) Idempotent Processing Option 3: Conflict-free Replicated Datatypes (CRDTs) o Achieve agreement without explicit coordination o Custom data structures, composable processing steps o Many implementations, but still an area of active research Common techniques o Remember what you saw (request id, idempotency key) o Remember that an item was deleted (“tombstone”) (Do *NOT* roll your own from first principles) @randyshoup linkedin.com/in/randyshoup
  • 47. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems o Event Duplication o Event Ordering
  • 48. Event Ordering • Problem: Events will arrive out of order o Network issues o Processing time o Redelivery @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-2 • Event-1 • Event-3
  • 49. Event Ordering • The consumer must process events correctly regardless of the order in which they arrive @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-2 • Event-1 • Event-3 • Event-1 • Event-2 • Event-3
  • 50. Event Ordering: (A) Impose Order Option 1: Sequence + Reorder in the message bus o Sequence number at the producer o Message bus queues messages, waits for gaps o Bus sends to consumer in order @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 [1] • Event-2 [2] • Event-3 [3] • Event-1 [1] • Event-2 [2] • Event-3 [3] • Event-1 [1] • Event-2 [2] • Event-3 [3] • Event-2 [2] • Event-1 [1] • Event-3 [3]
  • 51. Event Ordering: (A) Impose Order Option 2: Sequence + Reorder in the consumer o Sequence number / timestamp at the producer o Consumer reorders before processing @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 [1] • Event-2 [2] • Event-3 [3] • Event-2 [2] • Event-1 [1] • Event-3 [3] • Event-1 [1] • Event-2 [2] • Event-3 [3]
  • 52. Event Ordering: (B) Order-Independence Option 1: Order-independent semantics o E.g., count number of events @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-2 • Event-1 • Event-3 • +1 • +1 • +1
  • 53. Event Ordering: (B) Order-Independence Option 2: Notification + Read-back o Event is a notification: object id + type of change o Consumer “reads back” to the source service to get current state @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-2 • Event-1 • Event-3 • State = 2 • State = 2 • State = 3
  • 54. Event Ordering: (B) Order-Independence Option 3: Event Sourcing o Store all events in a log o Process / interpret later @randyshoup linkedin.com/in/randyshoup Producer ConsumerTransport • Event-1 • Event-2 • Event-3 • Event-2 • Event-1 • Event-3 Event-2 Event-1 Event-3 • Event-1 • Event-2 • Event-3
  • 55. Managing Data at Scale • Migrating to Microservices • Challenges of Data in Microservices • Challenges of Event-Driven Systems