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! I’ll use REST APIs 6 Orders Validate Returns? Order Inventory Fulfill Order 6
7 Synchronous request-response communication Leads to Tight point-to-point coupling 7
Clients know too much 8 Returns Inventory Fulfill Orders Validate
shifts in responsibility, redundancy 9 Retry? Retry? Fail Retry? 9
Making Changes is Risky 10 Change 1 0
Adding Services Requires Explicit Calls 11 Mistake Handler 1 1
REST = HTTP + JSON = SLOW 12 1 2
13 13 We can do better.
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 API Gateway
Clients know too much 16 Returns Inventory Fulfill Orders Validate
Shift in responsibility, redundancy 17 Auth Auth Auth
API Gateway 18 Returns Inventory API Gateway Orders
19 19 API Gateway ● Authentication ● Routing Responsibilit y ● Rate Limiting ● Logging and analytics
20 Anti-pattern
21 21 Service Mesh
22 North-South Traffic
23 East-West Traffic
Side-car 24
26 Proxy as sidecar: Proxy Proxy Proxy Proxy Proxy
27 I magically Who know all about I have a new IP cares? it! now. YOLO! Proxy
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
29 29 Event Driven
Making Changes is Risky 30 Change 3 0
Adding Services Requires Explicit Calls 31 Mistake Handler 3 1
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
33 Events are both facts and triggers
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()
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
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
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
38 Event Driven Microservices are Stateful
39
40 40 Schema
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
42 The medium is not the message.
43 43 This is a message { sessionId: 676fc8983gu563, timestamp: 1413215458, viewType: "propertyView", propertyId: 7879, loyaltyId: 6764532 origin: "promotion", ...... lots of metadata.... }
REST = HTTP + JSON = SLOW 44 4 4
Making Changes is Risky 45 Change 4 5
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)
47 {user_id: 53, timestamp: “June 28, 2017 4:00pm”} Booking Attribution service service new Date(timestamp) create table ( use_id number, timestamp number)
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)
49 APIs between services are Contracts In Event Driven World – Event Schemas ARE the API
50
51 So the flow is… Nightly build / Dev Test Prod merge MVN Plugin Test Registry Prod Registry
52 52 Serverless
53 Function as a Service Event < / > Launch VM Function Response Instance < / >
54 When nothing happens Event < / > Launch VM Function Response Instance < / >
55 At scale Event < / > Launch VM Function VM Function VM Instance Response Function VM Instance Function Instance < / > Instance < / > < / > < / >
56 Wait, this is super familiar Kafka Partitions Consume Event Container Function Container Order Instance Service! < / > < / > Produce
57 57 Up Next: Stateful Serverless
58 State is required ● Dynamic Rules ● Event enrichment ● Joining multiple events ● Aggregation
59 How You Probably Do State Create Order < / > Launch VM Function Order Created Instance Cloud Data < / > select from Store inventory … insert into Orders…
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?
61 But I really want this back:
62 Stateful Serverless Create Order < / > VM Validate Order < / > Order Status < / > Inventory, Rules
64 What’s Still missing? ● Durable functions ● Triggers and data ● Unified view of everywhere from data stores to current state functions
65
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