microservices in a streaming world there are many good
play

Microservices in a Streaming World There are many good reasons for - PowerPoint PPT Presentation

Microservices in a Streaming World There are many good reasons for building service-based systems Loose Coupling Bounded Contexts Autonomy Ease of scaling Composability But when we do, were building a distributed system


  1. Microservices in a Streaming World

  2. There are many good reasons for building service-based systems • Loose Coupling • Bounded Contexts • Autonomy • Ease of scaling • Composability

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

  4. This can be a bit tricky

  5. Monolithic & Centralised Approaches Shared, mutable state

  6. Decentralisation

  7. Stream Processing is a bit different batch analytics => real time => at scale => accurately

  8. and comes with an interesting toolset

  9. Stream Processing Business Applications Toolset

  10. Some fundamental patterns of distributed systems

  11. Request / Response

  12. Mediator / Workflow Request/Response

  13. Event Driven Async / Fire and Forget

  14. Request/Response vs. Event Based • Simple • Requires Broker • Synchronous • Fire & Forget • Event Driven • Polling • Good decoupling • Full decoupling

  15. SOA / Microservices Message Broker Request/Response Event Based

  16. Combinations Request/ Response Event- Based

  17. Combinations Withdraw Check Funds £100 I need Account money Service ReST Async Message Broker General Fraud Customer Ledger Statements Detection

  18. Services generally eschew shared, mutable state

  19. How do we put these things together?

  20. Request/Response

  21. Request/Response Request ReST Response

  22. Request/Response + Registry Request ReST Response Registry

  23. Asynchronous and Event-Based Communication

  24. Queues

  25. Point to Point Service A Service B

  26. Load Balancing Instance 1 Instance 2 Single message allocation has scalability issues

  27. Batched Allocation Instance 1 Instance 2 Throughput!

  28. Lose Ordering Guarantees Instance 1 Fail! Instance 2

  29. Topics

  30. Topics are Broadcast Consumer Broker broadcast Consumer

  31. Topics Retain Ordering Broker Instance 1 Buys Trades Sells Instance 2

  32. Even when services fail Instance 1 Broker Fail! Buys Trades Sells Instance 2 We retain ordering, but we have to detect & reprovision

  33. A Few Implications

  34. Queues Lose Ordering Guarantees at Scale Worker 1 Worker 2 Fail!

  35. Topics don’t provide availability Broker Buys Trades Sells

  36. Messages are Transient Broker Buys Trades Sells

  37. Is there another way?

  38. A Distributed Log Kafka is one example

  39. Think back to the queue example Batch Batch

  40. Shard on the way in

  41. Each shard is a queue Strong Ordering (in shard). Good concurrency.

  42. Each consuming service is assigned a “personal set” of queues each little queue is sent to only one service in a group

  43. Services instances naturally rebalance on failure Service instance dies, data is redirected, ordering guarantees remain

  44. Very Scalable, Very High Throughput Sharded In, Sharded Out

  45. Reduces to a globally ordered queue

  46. Fault Tolerance

  47. The Log Append only Single seek & scan messages don’t need to be transient!

  48. Cleaning the Log Delete old segments

  49. Cleaning the Log K1 V1 K1 V2 K1 V3 K2 V1 K2 V2 K1 V4 K2 V3 Delete old versions that share the same key

  50. • Scalable multiprocessing • Strong partition-based ordering • Efficient data retention • Always on

  51. So how is this useful for microservices?

  52. Build ‘Always On’ Services Rely on Fault Tolerant Broker

  53. Load Balance Services Load Balance Services (with strong ordering)

  54. Fault Tolerant Services Services automatically fail over (retaining ordering)

  55. Services can return back to old messages in the log Rewind & Replay

  56. Compacted Topics are Interesting K1 V1 K1 V2 K1 V3 K2 V1 K2 V2 K1 V4 K2 V3

  57. Lets take a little example

  58. Getting Exchange Rates I Exchange need Rate exchange Service rates! USD/GBP = 0.71 EUR/GBP = 0.77 USD/INR = 67.7 USD/AUD = 1.38 EUR/JPY = 114.41 …

  59. Option1: Request Response rate for USD/GBP? I Exchange need Rate exchange Service rates! 0.71

  60. Option 2: Publish Subscribe I Exchange need Rate exchange Service rates! ETL Accumulate current state

  61. Option 3: Accumulate in Compacted Stream Publish to clients Publish all rate events Exchange USD/GBP = 0.71 Rate EUR/GBP = 0.77 USD/INR = 67.7 USD/AUD = 1.38 Service EUR/JPY = 114.41 … Get all exchange rates Broker retains latest versions

  62. Is it a stream or is it a table? transitory stateful

  63. Datasets can live in the broker! books trades ex- risk results rates

  64. Service Backbone Scalable, Fault Tolerant, Concurrent, Strongly Ordered, Stateful

  65. … lets add in stream processing

  66. What is stream processing? Max(price) From orders where ccy=‘GBP’ over 1 day window emitting every second Continuous Queries.

  67. What is stream processing engine? Query Engine Query vs Engine Index Data Database Stream Processor Finite, well defined source Infinite, poorly defined source

  68. Windowing Fixed (tumbling) Sliding For unordered or unpredictable streams

  69. Features: similar to database query engine Window Aggr- Join Filter View egate

  70. KStreams & KTables KStream Streaming Data stream Join Stored Data Compacted stream KTable

  71. A little example…

  72. Buying Lunch Abroad Text Message: ££ Buy Payments $$ Service $$ Notification $$ Service Amount in ££ Exchange Rates Service

  73. Request-Response Option Text Message: ££ Buy Payments Service Amount in ££ Join etc Exchange Rates Iterative join Service over the network

  74. ETL Option Text Message: ££ Buy Payments Service Amount in ££ ETL Exchange Rates Service ETL Join etc

  75. Stream Processor Option Text Message: ££ Buy Payments Service join etc Exchange Stream Rates Processor Service

  76. Buying Lunch Abroad KStream Looks like Payments an infinite stream Looks like a table Exchange (compacted Rates stream) KTable

  77. Buying Lunch Abroad Payments • Filter(ccy<>’GBP’) • Join on ccy • Calculate GBP • Send text message Exchange Rates buffering

  78. Local DB (fast joins) KStream Topic pre-populate Compacted Topic

  79. KTables can also be written to - they’re backed by the broker KStream Topic Compacted Topic KTable Manage intermediary state

  80. Scales Out (MPP)

  81. These tools are pretty handy for managing decentralised services

  82. Talk our own data model Query View Data Stream

  83. Handle Unpredictability Late trades 9am 5pm

  84. Joining Services Payments Join Exchange Rates

  85. Duality between Stream and Table KStream Join KTable

  86. More Complex Use Cases Trades Valuations Books Customers General Ledger

  87. Practical mechanism for managing data intensive, loosely coupled services • Stateful streams live inside the Log • Data extracted quickly! books trades • Fast, local joins, over ex- risk results rates large datasets • HA pre-caching • Manage intermediary state • Just a simple library (over Kafka)

  88. There is much more to stream processing it is grounded in the world of big-data analytics

  89. Simple Approaches Just a library (over Kafka)

  90. Keeping Services Consistent

  91. Problem: No BGBSS Big Global Bag of State in the Sky

  92. How to you provide the accuracy of this

  93. In this?

  94. Centralised vs Federated Centralised Distributed consistency model consistency model

  95. One problem is failure

  96. Duplicate messages are inevitable have I seen this before?

  97. Make Services Idempotent try 1 try 2 try 3 try 4

  98. Stream processors have to solve this problem

  99. Exactly Once not available in Kafka… yet

Recommend


More recommend