beyond microservices streams state and scalability
play

Beyond Microservices: Streams, State and Scalability Gwen Shapira, - PowerPoint PPT Presentation

1 Beyond Microservices: Streams, State and Scalability Gwen Shapira, Engineering Manager @gwenshap 2 In the beginning 3 We Have Microservices 3 4 We Microservices 4 5 They need to communicate 5 I know! Ill use REST APIs 6


  1. 1 Beyond Microservices: Streams, State and Scalability Gwen Shapira, Engineering Manager @gwenshap

  2. 2 In the beginning…

  3. 3 We Have Microservices 3

  4. 4 We Microservices 4

  5. 5 They need to communicate 5

  6. I know! I’ll use REST APIs 6 Orders Validate Returns? Order Inventory Fulfill Order 6

  7. 7 Synchronous request-response communication Leads to Tight point-to-point coupling 7

  8. Clients know too much 8 Returns Inventory Fulfill Orders Validate

  9. shifts in responsibility, redundancy 9 Retry? Retry? Fail Retry? 9

  10. Making Changes is Risky 10 Change 1 0

  11. Adding Services Requires Explicit Calls 11 Mistake Handler 1 1

  12. REST = HTTP + JSON = SLOW 12 1 2

  13. 13 13 We can do better.

  14. 14 Nice to meet you! ● Moving data around for 20 years ● Engineering Manager at Confluent ● Apache Kafka Committer ● Wrote a book or two ● Tweets a lot - @gwenshap

  15. 15 15 API Gateway

  16. Clients know too much 16 Returns Inventory Fulfill Orders Validate

  17. Shift in responsibility, redundancy 17 Auth Auth Auth

  18. API Gateway 18 Returns Inventory API Gateway Orders

  19. 19 19 API Gateway ● Authentication ● Routing Responsibilit y ● Rate Limiting ● Logging and analytics

  20. 20 Anti-pattern

  21. 21 21 Service Mesh

  22. 22 North-South Traffic

  23. 23 East-West Traffic

  24. Side-car 24

  25. 26 Proxy as sidecar: Proxy Proxy Proxy Proxy Proxy

  26. 27 I magically Who know all about I have a new IP cares? it! now. YOLO! Proxy

  27. 28 Error? LOL. I’m No worries! I can recover from dropping 99% Lets retry every errors without of the retries. millisecond forever drowning Proxy

  28. 29 29 Event Driven

  29. Making Changes is Risky 30 Change 3 0

  30. Adding Services Requires Explicit Calls 31 Mistake Handler 3 1

  31. 32 1. Tell others what to do Broadcast what I do Logic (commands) Logic 2. Ask questions (queries) Logic Logic Kafka Logic Logic Logic Others work out what to do Logic Queries use local cache

  32. 33 Events are both facts and triggers

  33. 34 Buying an iPad (with REST) Webserver Submit - Orders Service calls Shipping Order Service to tell it to ship item. - Shipping service looks up Customer Orders Shipping Service address to ship to (from Service Service Customer Service) shipOrder() getCustomer()

  34. 35 Using events for Notification Notification Webserver Submit Order - Orders Service no longer knows about the Shipping service (or Customer Orders Shipping Service Service Service any other service). Events are REST fire and forget. Order getCustomer() Created

  35. 36 Webserver Using events to Data is share facts Submit replicated Order - Call to Customer service is gone. Customer Orders Shipping - Instead data in replicated, as Service Service Service events, into the shipping service, where it is queried locally. . Customer Order Updated Created

  36. 37 37 DB for Each ● It is safe: ● Custom Microservice? They are all projection just the derived from same data each service stream of events needs. ● Reduced ● Low latency dependencies

  37. 38 Event Driven Microservices are Stateful

  38. 39

  39. 40 40 Schema

  40. 41 1. Tell others what to do Broadcast what I do Logic (commands) Logic 2. Ask questions (queries) Logic Logic Kafka Logic Logic Logic Others work out what to do Logic Queries use local cache

  41. 42 The medium is not the message.

  42. 43 43 This is a message { sessionId: 676fc8983gu563, timestamp: 1413215458, viewType: "propertyView", propertyId: 7879, loyaltyId: 6764532 origin: "promotion", ...... lots of metadata.... }

  43. REST = HTTP + JSON = SLOW 44 4 4

  44. Making Changes is Risky 45 Change 4 5

  45. 46 There are lots of dependencies {user_id: 53, timestamp: 1497842472} Booking Attribution service service new Date(timestamp) create table ( use_id number, timestamp number)

  46. 47 {user_id: 53, timestamp: “June 28, 2017 4:00pm”} Booking Attribution service service new Date(timestamp) create table ( use_id number, timestamp number)

  47. 48 Moving fast and breaking things {user_id: 53, timestamp: “June 28, 2017 4:00pm”} Booking Attribution service service new Date(timestamp) create table ( use_id number, timestamp number)

  48. 49 APIs between services are Contracts In Event Driven World – Event Schemas ARE the API

  49. 50

  50. 51 So the flow is… Nightly build / Dev Test Prod merge MVN Plugin Test Registry Prod Registry

  51. 52 52 Serverless

  52. 53 Function as a Service Event < / > Launch VM Function Response Instance < / >

  53. 54 When nothing happens Event < / > Launch VM Function Response Instance < / >

  54. 55 At scale Event < / > Launch VM Function VM Function VM Instance Response Function VM Instance Function Instance < / > Instance < / > < / > < / >

  55. 56 Wait, this is super familiar Kafka Partitions Consume Event Container Function Container Order Instance Service! < / > < / > Produce

  56. 57 57 Up Next: Stateful Serverless

  57. 58 State is required ● Dynamic Rules ● Event enrichment ● Joining multiple events ● Aggregation

  58. 59 How You Probably Do State Create Order < / > Launch VM Function Order Created Instance Cloud Data < / > select from Store inventory … insert into Orders…

  59. 60 We can do a bit better What’s the latest with my order? < / > Select order_id, customer_name, product, quantity, price, state from orders where state != “CLOSED” VM Function Instance Cloud Data < / > Order is processing Store Not shipped yet. Maybe check DB?

  60. 61 But I really want this back:

  61. 62 Stateful Serverless Create Order < / > VM Validate Order < / > Order Status < / > Inventory, Rules

  62. 64 What’s Still missing? ● Durable functions ● Triggers and data ● Unified view of everywhere from data stores to current state functions

  63. 65

  64. 66 Resources ● http://christophermeiklejohn.com/serverless/2019/05/25/stateful-serverless-bank-example.html ● https://www.infoq.com/articles/service-mesh-promise-peril/ ● https://blog.getambassador.io/api-gateway-vs-service-mesh-104c01fa4784 ● https://www.nginx.com/blog/building-microservices-using-an-api-gateway/ ● https://wecode.wepay.com/posts/migrating-apis-from-rest-to-grpc-at-wepay ● https://content.pivotal.io/slides/microservices-events-and-breaking-the-data-monolith-with-kafka ● https://www.slideshare.net/ConfluentInc/event-sourcing-stream-processing-and-serverless-ben- stopford-confluent-kafka-summit-sf-2019

Recommend


More recommend