microservices in a streaming world · even when services fail trades buys sells fail! broker we...

138
Microservices in a Streaming World

Upload: others

Post on 25-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Microservices in a Streaming World

Page 2: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

There are many good reasons for building service-based systems

• Loose Coupling

• Bounded Contexts

• Autonomy

• Ease of scaling

• Composability

Page 3: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

But when we do, we’re building a distributed system

Page 4: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

This can be a bit tricky

Page 5: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Monolithic & Centralised Approaches

Shared, mutable state

Page 6: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Decentralisation

Page 7: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications
Page 8: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Stream Processing is a bit different

batch analytics => real time => at scale => accurately

Page 9: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

and comes with an interesting toolset

Page 10: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Stream Processing Toolset

Business Applications

Page 11: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Some fundamental patterns of distributed

systems

Page 12: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Request / Response

Page 13: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Mediator / Workflow

Request/Response

Page 14: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Event Driven

Async / Fire and Forget

Page 15: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Event Based

• Simple

• Synchronous

• Event Driven

• Good decoupling

• Requires Broker

• Fire & Forget

• Polling

• Full decoupling

Request/Response vs.

Page 16: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

SOA / Microservices

Message Broker

Event Based Request/Response

Page 17: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Combinations

Event- Based

Request/Response

Page 18: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

CombinationsWithdraw

£100AccountService

GeneralLedger

CustomerStatements

FraudDetection

Check Funds

Async Message Broker

I need moneyReST

Page 19: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Services generally eschew shared, mutable state

Page 20: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

How do we put these things together?

Page 21: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Request/Response

Page 22: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Request/Response

Request

Response

ReST

Page 23: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Request/Response + Registry

Registry

Request

Response

ReST

Page 24: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Asynchronous and Event-Based

Communication

Page 25: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Queues

Page 26: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Point to Point

Service A Service B

Page 27: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Load Balancing

Instance 2

Instance 1

Single message allocation has scalability issues

Page 28: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Batched AllocationInstance 1

Instance 2

Throughput!

Page 29: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Lose Ordering Guarantees

Fail!

Instance 1

Instance 2

Page 30: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Topics

Page 31: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Topics are Broadcast

Consumer

Consumer

Broker broadcast

Page 32: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Topics Retain Ordering

Trades

Buys

Sells

Broker Instance 1

Instance 2

Page 33: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Even when services fail

Trades

Buys

Sells

Fail!Broker

We retain ordering, but we have to detect & reprovision

Instance 1

Instance 2

Page 34: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

A Few Implications

Page 35: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Queues Lose Ordering Guarantees at Scale

Fail!

Worker 1

Worker 2

Page 36: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Trades

Buys

Sells

Topics don’t provide availability

Broker

Page 37: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Trades

Buys

Sells

Messages are Transient

Broker

Page 38: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Is there another way?

Page 39: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

A Distributed LogKafka is one example

Page 40: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Think back to the queue example

Batch

Batch

Page 41: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Shard on the way in

Page 42: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Each shard is a queue

Strong Ordering (in shard). Good concurrency.

Page 43: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Each consuming service is assigned a “personal set” of queues

each little queue is sent to only one service in a group

Page 44: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Services instances naturally rebalance on failure

Service instance dies, data is redirected, ordering guarantees remain

Page 45: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Very Scalable, Very High Throughput

Sharded In, Sharded Out

Page 46: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Reduces to a globally ordered queue

Page 47: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Fault Tolerance

Page 48: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

The Log

Single seek & scan

Appendonly

messages don’t need to be transient!

Page 49: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Cleaning the Log

Delete old segments

Page 50: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Cleaning the Log

Delete old versions that share the same key

K1K1K1K2K2

K2K1

V1

V1

V2V3

V2V4V3

Page 51: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

• Scalable multiprocessing

• Strong partition-based ordering

• Efficient data retention

• Always on

Page 52: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

So how is this useful for microservices?

Page 53: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Build ‘Always On’ Services

Rely on Fault Tolerant Broker

Page 54: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Load Balance Services

Load Balance Services(with strong ordering)

Page 55: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Fault Tolerant Services

Services automatically fail over

(retaining ordering)

Page 56: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Services can return back to old messages in the log

Rewind & Replay

Page 57: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Compacted Topics are Interesting

K1K1K1K2K2

K2K1

V1

V1

V2V3

V2V4V3

Page 58: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Lets take a little example

Page 59: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Getting Exchange Rates

ExchangeRate

Service

USD/GBP = 0.71EUR/GBP = 0.77USD/INR = 67.7USD/AUD = 1.38EUR/JPY = 114.41…

Ineed

exchange rates!

Page 60: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Option1: Request Response

rate for USD/GBP?

0.71

ExchangeRate

Service

I need

exchange rates!

Page 61: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Option 2: Publish Subscribe

ExchangeRate

Service

Accumulate current state

ETL

Ineed

exchange rates!

Page 62: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Option 3: Accumulate in Compacted Stream

ExchangeRate

Service

Get all exchange rates

Publish to clients

USD/GBP = 0.71EUR/GBP = 0.77USD/INR = 67.7USD/AUD = 1.38EUR/JPY = 114.41…

Broker retainslatest versions

Publish all rate events

Page 63: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Is it a stream or is it a table?

transitory stateful

Page 64: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Datasets can live in the broker!

trades books

risk resultsex-rates

Page 65: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Service BackboneScalable, Fault Tolerant, Concurrent, Strongly Ordered, Stateful

Page 66: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

… lets add in stream processing

Page 67: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Max(price)From orderswhere ccy=‘GBP’over 1 day windowemitting every second

What is stream processing?

Continuous Queries.

Page 68: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

What is stream processing engine?

DataIndex

QueryEngine

QueryEnginevs

DatabaseFinite, well defined source

Stream ProcessorInfinite, poorly defined source

Page 69: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Windowing

For unordered or unpredictable streams

Sliding

Fixed(tumbling)

Page 70: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Features: similar to database query engine

JoinFilterAggr-egate View

Window

Page 71: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

KStreams & KTables

stream

Compactedstream

Join

Streaming Data

Stored Data

KStream

KTable

Page 72: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

A little example…

Page 73: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Buying Lunch Abroad

PaymentsService

ExchangeRates

Service

Buy

Notification Service

Amount in ££

$$

$$

Text Message: ££

$$

Page 74: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Request-Response Option

PaymentsService

ExchangeRates

Service

Buy

Amount in ££

Join etc

Text Message: ££

Iterative join over the network

Page 75: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

ETL Option

PaymentsService

ExchangeRates

Service

Buy

Amount in ££

ETL

ETLJoin etc

Text Message: ££

Page 76: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Stream Processor Option

PaymentsService

ExchangeRates

Service

Buy

StreamProcessor

joinetc

Text Message: ££

Page 77: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Buying Lunch Abroad

Payments

ExchangeRates

Looks like a table

(compactedstream)

Looks like an infinite stream

KStream

KTable

Page 78: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Buying Lunch Abroad

Payments

ExchangeRates

• Filter(ccy<>’GBP’)• Join on ccy• Calculate GBP• Send text message

buffering

Page 79: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Local DB (fast joins)

Topic

CompactedTopic

KStream

pre-populate

Page 80: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

KTables can also be written to - they’re backed by the broker

Manage intermediary

state

KStream

KTable

Topic

CompactedTopic

Page 81: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Out (MPP)

Page 82: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

These tools are pretty handy

for managing decentralised services

Page 83: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Talk our own data model

DataStream

View

Query

Page 84: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Handle Unpredictability

9am 5pm

Late trades

Page 85: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Joining Services

Payments

ExchangeRates

Join

Page 86: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Duality between Stream and Table

Join

KStream

KTable

Page 87: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

More Complex Use CasesTrades Valuations

Books Customers

General Ledger

Page 88: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

trades books

risk resultsex-rates

Practical mechanism for managing data intensive, loosely coupled services

• Stateful streams live inside the Log

• Data extracted quickly!

• Fast, local joins, over large datasets

• HA pre-caching

• Manage intermediary state

• Just a simple library (over Kafka)

Page 89: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

There is much more to stream processingit is grounded in the world of big-data analytics

Page 90: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Simple Approaches

Just a library (over Kafka)

Page 91: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Keeping Services Consistent

Page 92: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Big Global Bag of State in the Sky

Problem: No BGBSS

Page 93: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

How to you provide the accuracy of this

Page 94: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

In this?

Page 95: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Centralised vs Federated

Centralised consistency model

Distributed consistency model

Page 96: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

One problem is failure

Page 97: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Duplicate messages are inevitable

have I seen this before?

Page 98: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Make Services Idempotent

try 1

try 2

try 3

try 4

Page 99: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Stream processors have to solve this problem

Page 100: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Exactly Once

not available in Kafka… yet

Page 101: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

So what do we have?

Page 102: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Use Both Approaches

Event- Based

Request/Response

Page 103: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Queued Delivery System

Ordered queue

Page 104: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Page 105: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Page 106: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Page 107: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Page 108: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Built In Fault Tolerance

Page 109: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Runs Always On

Page 110: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

For Services Too

Page 111: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Load Balance

Page 112: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

continue through failure

Page 113: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

with history stored in the Log

Page 114: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

Extending to any number of services

Page 115: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

With any data throughput

Page 116: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

With any data throughput

Page 117: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

With any data throughput

Page 118: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

powerful tools for slicing and dicing streams

Page 119: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

the declarative processing of

datajoin

filteraggregate

Page 120: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

at any throughput

Page 121: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

leveraging fast local

persistence

Page 122: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

backed up to the log

Page 123: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

easily join streaming services

Page 124: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Blend KStreams

and KTables

Page 125: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

trades books

risk resultsex-rates

with data living in the stream

Page 126: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

but retaining loose coupling

trades books

risk resultsex-rates

Page 127: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Scales Horizontally

with strong ordering and repeatability guarantees

(eventually)

Page 128: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

so…

Page 129: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Microservices push us away from shared, mutable state

Page 130: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Big Global Bag of State in the Sky

Away from BGBSS’s

Page 131: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

This means data is increasingly remote

Page 132: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Sure, you can collect it all

copy copy

copy

copycopy

copy

copy

ETL

ETL

ETL ETL

ETL

ETL

Page 133: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

can be a lot of work

Page 134: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Or you can look it all up

getget

get

getget

get

get

get, get, get, get

Page 135: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

but that doesn’t scale well(with system complexity or with data throughput)

Page 136: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Better to embrace decentralistion

Page 137: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

We need a decentralised toolset to do this

trades books

risk resultsex-

rates

Page 138: Microservices in a Streaming World · Even when services fail Trades Buys Sells Fail! Broker We retain ordering, but we have to detect & reprovision Instance 1 Instance 2. A Few Implications

Keep it simple, Keep it moving