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

beyond microservices streams state and scalability
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

Beyond Microservices: Streams, State and Scalability

Gwen Shapira, Engineering Manager @gwenshap

slide-2
SLIDE 2

2

In the beginning…

slide-3
SLIDE 3

3

We Have Microservices

3

slide-4
SLIDE 4

4

We Microservices

4

slide-5
SLIDE 5

5

They need to communicate

5

slide-6
SLIDE 6

6

6

I know! I’ll use REST APIs

Orders Returns? Inventory Fulfill Order Validate Order

slide-7
SLIDE 7

7

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

7

slide-8
SLIDE 8

8

Clients know too much

Orders Inventory Returns Validate Fulfill

slide-9
SLIDE 9

9

9

shifts in responsibility, redundancy

Fail

Retry? Retry? Retry?

slide-10
SLIDE 10

10

1

Making Changes is Risky

Change

slide-11
SLIDE 11

11

1 1

Adding Services Requires Explicit Calls

Mistake Handler

slide-12
SLIDE 12

12

1 2

REST = HTTP + JSON = SLOW

slide-13
SLIDE 13

13 13

We can do better.

slide-14
SLIDE 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
slide-15
SLIDE 15

15 15

API Gateway

slide-16
SLIDE 16

16

Clients know too much

Orders Inventory Returns Validate Fulfill

slide-17
SLIDE 17

17

Shift in responsibility, redundancy

Auth Auth Auth

slide-18
SLIDE 18

18

API Gateway

Returns Inventory Orders API Gateway

slide-19
SLIDE 19

19 19

API Gateway Responsibilit y

  • Authentication
  • Routing
  • Rate Limiting
  • Logging and

analytics

slide-20
SLIDE 20

20

Anti-pattern

slide-21
SLIDE 21

21 21

Service Mesh

slide-22
SLIDE 22

22

North-South Traffic

slide-23
SLIDE 23

23

East-West Traffic

slide-24
SLIDE 24

24

Side-car

slide-25
SLIDE 25

26

Proxy as sidecar:

Proxy Proxy Proxy Proxy Proxy

slide-26
SLIDE 26

27

Proxy

I have a new IP

  • now. YOLO!

Who cares? I magically know all about it!

slide-27
SLIDE 27

28

Proxy

I can recover from errors without drowning Error? No worries! Lets retry every millisecond forever

  • LOL. I’m

dropping 99%

  • f the retries.
slide-28
SLIDE 28

29 29

Event Driven

slide-29
SLIDE 29

30

3

Making Changes is Risky

Change

slide-30
SLIDE 30

31

3 1

Adding Services Requires Explicit Calls

Mistake Handler

slide-31
SLIDE 31

32

Logic Logic Logic Logic

1. Tell others what to do (commands) 2. Ask questions (queries)

Logic Logic Logic Logic

Broadcast what I do Kafka Others work out what to do Queries use local cache

slide-32
SLIDE 32

33

Events are both facts and triggers

slide-33
SLIDE 33

34

Buying an iPad (with REST)

  • Orders Service calls Shipping

Service to tell it to ship item.

  • Shipping service looks up

address to ship to (from Customer Service)

Submit Order shipOrder() getCustomer() Orders Service Shipping Service Customer Service Webserver

slide-34
SLIDE 34

35

Using events for Notification

  • Orders Service no longer knows

about the Shipping service (or any other service). Events are fire and forget.

Submit Order Order Created getCustomer()

REST Notification

Orders Service Shipping Service Customer Service Webserver

slide-35
SLIDE 35

36

Using events to share facts

  • Call to Customer service is gone.
  • Instead data in replicated, as

events, into the shipping service, where it is queried locally. .

Customer Updated Submit Order Order Created

Data is replicated

Orders Service Shipping Service Customer Service Webserver

slide-36
SLIDE 36

37 37

DB for Each Microservice?

  • It is safe:

They are all derived from same stream of events

  • Custom

projection just the data each service needs.

  • Reduced

dependencies

  • Low latency
slide-37
SLIDE 37

38

Event Driven Microservices are

Stateful

slide-38
SLIDE 38

39

slide-39
SLIDE 39

40 40

Schema

slide-40
SLIDE 40

41

Logic Logic Logic Logic

1. Tell others what to do (commands) 2. Ask questions (queries)

Logic Logic Logic Logic

Broadcast what I do Kafka Others work out what to do Queries use local cache

slide-41
SLIDE 41

42

The medium is not the message.

slide-42
SLIDE 42

43 43

This is a message

{ sessionId: 676fc8983gu563, timestamp: 1413215458, viewType: "propertyView", propertyId: 7879, loyaltyId: 6764532

  • rigin: "promotion",

...... lots of metadata.... }

slide-43
SLIDE 43

44

4 4

REST = HTTP + JSON = SLOW

slide-44
SLIDE 44

45

4 5

Making Changes is Risky

Change

slide-45
SLIDE 45

46

There are lots of dependencies

Booking service {user_id: 53, timestamp: 1497842472} create table ( use_id number, timestamp number) new Date(timestamp) Attribution service

slide-46
SLIDE 46

47

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

slide-47
SLIDE 47

48

Moving fast and breaking things

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

slide-48
SLIDE 48

49

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

slide-49
SLIDE 49

50

slide-50
SLIDE 50

51

So the flow is…

Dev Nightly build / merge Prod Test Registry Prod Registry Test MVN Plugin

slide-51
SLIDE 51

52 52

Serverless

slide-52
SLIDE 52

53

Function as a Service

Event

< / >

Response

VM Function Instance

< / >

Launch

slide-53
SLIDE 53

54

When nothing happens

Event

< / >

Response

VM Function Instance

< / >

Launch

slide-54
SLIDE 54

55

At scale

Event

< / >

Response

VM Function Instance

< / >

Launch

VM Function Instance

< / >

VM Function Instance

< / >

VM Function Instance

< / >

slide-55
SLIDE 55

56

Consume Event Produce

Container Function Instance

< / >

Wait, this is super familiar

Kafka Partitions Container Order Service!

< / >

slide-56
SLIDE 56

57 57

Up Next: Stateful Serverless

slide-57
SLIDE 57

58

State is required

  • Dynamic Rules
  • Event enrichment
  • Joining multiple events
  • Aggregation
slide-58
SLIDE 58

59

How You Probably Do State

Create Order

< / >

Order Created

VM Function Instance

< / >

Launch

Cloud Data Store

select from inventory … insert into Orders…

slide-59
SLIDE 59

60

We can do a bit better

Select order_id, customer_name, product, quantity, price, state from

  • rders

where state != “CLOSED”

< / > VM Function Instance < / > Cloud Data Store What’s the latest with my order? Maybe check DB? Order is processing Not shipped yet.

slide-60
SLIDE 60

61

But I really want this back:

slide-61
SLIDE 61

62

VM Create Order < / > Order Status < / > Validate Order < / > Inventory, Rules

Stateful Serverless

slide-62
SLIDE 62

64

  • Durable functions

everywhere

  • Triggers and data

from data stores to functions

What’s Still missing?

  • Unified view of

current state

slide-63
SLIDE 63

65

slide-64
SLIDE 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