How smart APIs are different. @berndruecker Some Service Some - - PowerPoint PPT Presentation

how smart apis are different
SMART_READER_LITE
LIVE PREVIEW

How smart APIs are different. @berndruecker Some Service Some - - PowerPoint PPT Presentation

Moving beyond request-reply: How smart APIs are different. @berndruecker Some Service Some Some Service Service Some Service But keep it local! Some Service Failure will happen. Be resilient. Accept it! Some Some Service Service


slide-1
SLIDE 1

Moving beyond request-reply: How smart APIs are different.

@berndruecker

slide-2
SLIDE 2
slide-3
SLIDE 3

Some Service Some Service Some Service Some Service Some Service Some Service Some Service

Failure will happen. Accept it! But keep it local! Be resilient.

slide-4
SLIDE 4

Photo by Tookapic, available under Creative Commons CC0 1.0 license.

slide-5
SLIDE 5

„There was an error while sending your boarding pass“

slide-6
SLIDE 6

Check-in Web-UI

Me

Current situation

slide-7
SLIDE 7

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

slide-8
SLIDE 8

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

slide-9
SLIDE 9

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the good part

Circuit breaker

slide-10
SLIDE 10
slide-11
SLIDE 11

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

slide-12
SLIDE 12

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

slide-13
SLIDE 13

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Stateful Retry

slide-14
SLIDE 14
slide-15
SLIDE 15

We are having some technical difficulties and cannot present you your boarding pass right away. But we do actively retry ourselves, so lean back, relax and we will send it

  • n time.
slide-16
SLIDE 16

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

slide-17
SLIDE 17

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

Stateful Retry

slide-18
SLIDE 18

Warning: Contains Opinion

slide-19
SLIDE 19

Berlin, Germany

http://berndruecker.io/ mail@berndruecker.io @berndruecker

Bernd Ruecker

Co-founder and Chief T echnologist of Camunda

slide-20
SLIDE 20

Check-In

You can use a workflow engine (=durable state machine)!

Barcode

REST

Stateful retry

slide-21
SLIDE 21

Want to see code?

https://github.com/berndruecker/flowing-retail

slide-22
SLIDE 22

has to implement

Retry

has to implement

Idempotency

Client Service Provider

slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25

Don‘t worry, it will happen safely – even if you loose connection. Feel free to reload this page any time!

slide-26
SLIDE 26

Photo by pixabay, available under Creative Commons CC0 1.0 license.

slide-27
SLIDE 27

Requirement: Idempotency of services!

Photo by pixabay, available under Creative Commons CC0 1.0 license.

slide-28
SLIDE 28

Requirement: Idempotency of services!

Photo by Chr.Späth, available under Public Domain.

slide-29
SLIDE 29

Make every service idempotent!

Credit Card Payment

Charge Credit Card cardNumber amount Charge Credit Card cardNumber amount transactionId

Not Not idempotent Idempotent

charge

Generally: create Ids as soon as possible

slide-30
SLIDE 30

Distributed systems introduce complexity you have to tackle!

Credit Card Payment

REST

slide-31
SLIDE 31

Distributed systems

slide-32
SLIDE 32

It is impossible to differentiate certain failure scenarios.

Independant of communication style!

Service Provider Client

slide-33
SLIDE 33

Distributed systems introduce complexity you have to tackle!

Credit Card Payment

REST

slide-34
SLIDE 34

Distributed systems introduce complexity you have to tackle!

Credit Card Payment

REST

Cancel charge

slide-35
SLIDE 35

Being able to implement long running services is essential for smart APIs

(on a technical level)

@berndruecker

slide-36
SLIDE 36

Example

Booking Payment

Retrieve Payment

@berndruecker

slide-37
SLIDE 37

Example

Booking Payment Credit Card

Retrieve Payment

@berndruecker

slide-38
SLIDE 38

Example

Booking Payment Credit Card

Retrieve Payment Rejected

@berndruecker

slide-39
SLIDE 39

Example

Booking Payment

If the credit card was rejected, the customer can provide new details

Credit Card

Retrieve Payment Rejected Rejected

@berndruecker

slide-40
SLIDE 40

Example

Booking Payment

If the credit card was rejected, the customer can provide new details

Credit Card

Retrieve Payment Rejected Rejected

@berndruecker

A few smart god services tell anemic CRUD services what to do

Sam Newmann

slide-41
SLIDE 41

Payment failed

Who is responsible to deal with problems?

Booking Payment

If the credit card was rejected, the customer can provide new details

Credit Card

Retrieve Payment Rejected Payment received

@berndruecker

slide-42
SLIDE 42

Payment failed

Long running services

Booking Payment Credit Card

Retrieve Payment Rejected Payment received

Smart endpoints are potentially long-running @berndruecker

slide-43
SLIDE 43

Being able to implement long running services is essential for smart APIs

(on a business level)

@berndruecker

slide-44
SLIDE 44

Long running services require async communication

slide-45
SLIDE 45

Synchronous communication

slide-46
SLIDE 46

Synchronous communication is the crystal meth of distributed programming

T

  • dd Montgomery and Martin Thompson

in “How did we end up here” at GOT

O Chicago 2015

slide-47
SLIDE 47

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Asynchronous communication

You need to monitor timeouts

slide-48
SLIDE 48

Workflow…

slide-49
SLIDE 49

Workflow…

slide-50
SLIDE 50

Being able to implement long running services makes it easy to get async

@berndruecker

slide-51
SLIDE 51

Can your company leverage your hipster architecture?

Shutterstock

You need to change busi sines ess pr processes es and customer er expe perience ience!

slide-52
SLIDE 52

Example

@berndruecker

slide-53
SLIDE 53

Example

Payment Seat Reservation Booking Ticket Generation

slide-54
SLIDE 54

Example

@berndruecker sync

slide-55
SLIDE 55

Example

@berndruecker

slide-56
SLIDE 56

Weaknesses

Payment Seat Reservation Booking Ticket Generation

REST

slide-57
SLIDE 57

Weaknesses: Latency creep

Payment Seat Reservation Booking Ticket Generation

REST

300 ms 1150 + x ms 600 ms 250 ms

slide-58
SLIDE 58

Weaknesses: Availabiliy erosion

Payment Seat Reservation Booking Ticket Generation

REST

99 % uptime 99 % uptime 99 % uptime 96 % uptime

slide-59
SLIDE 59

And it is even hard to implement

Payment Seat Reservation Booking Ticket Generation

REST

slide-60
SLIDE 60

And it is even hard to implement

Payment Seat Reservation Booking Ticket Generation

REST

slide-61
SLIDE 61

T ypical pattern

Payment Seat Reservation Booking Ticket Generation

REST Simulate synchronicty by waiting (callback or polling)

slide-62
SLIDE 62

@berndruecker happy case failure case

Redesign your business process accordingly!

Or some interface to poll for status Sync in happy case Async response

slide-63
SLIDE 63

@berndruecker

Redesign your business process accordingly!

slide-64
SLIDE 64

Your business processes need to be more reactive!

@berndruecker https://www.reactivemanifesto.org/

slide-65
SLIDE 65

Yeah! Let‘s go reactive.

slide-66
SLIDE 66

Phil Calcado at QCon NYC 2019

slide-67
SLIDE 67

API API API API API API API

Microservices External Services Standard Software

„What the hell just happened?“

@berndruecker

slide-68
SLIDE 68

Example:

  • rder fulfillment via

dash button

Photo by 0xF2, available under Creative Commons BY-ND 2.0

  • license. https://www.flickr.com/photos/0xf2/29873149904/

@berndruecker

slide-69
SLIDE 69

Three steps…

@berndruecker

slide-70
SLIDE 70

(Micro-)services

Checkout Payment Inventory Shipment

@berndruecker

slide-71
SLIDE 71

Order Placed Payment Received Goods Fetched

Notification Checkout Payment Inventory Shipment

Event-driven architecture

@berndruecker

slide-72
SLIDE 72

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

@berndruecker

slide-73
SLIDE 73

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

@berndruecker

slide-74
SLIDE 74

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-75
SLIDE 75

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-76
SLIDE 76

The danger is that it's very easy to make nicely decoupled systems with event notification, without realizing that you're losing sight of that larger-scale flow, and thus set yourself up for trouble in future years.

https://martinfowler.com/articles/201701-event-driven.html @berndruecker

slide-77
SLIDE 77

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Order placed Payment received Goods shipped Goods fetched

Fetch the goods before the payment

@berndruecker

slide-78
SLIDE 78

Peer-to-peer event chains

Checkout Payment Inventory Shipment

Fetch the goods before the payment

Goods fetched Order placed Payment received Goods shipped

@berndruecker

slide-79
SLIDE 79

What we wanted

Photo by Lijian Zhang, available under Creative Commons SA 2.0 License and P..19 / CC BY-SA 4.0 @berndruecker

slide-80
SLIDE 80

Order

Extract the end-to-end responsibility

Checkout Payment Inventory Shipment

Payment received Order placed Retrieve payment

@berndruecker

slide-81
SLIDE 81

Order

Events & Commands

Checkout Payment Inventory Shipment

Payment received Order placed Retrieve payment

@berndruecker

Event Command

Fact, happened in the past, immutable Intend, Want s.th. to happen

slide-82
SLIDE 82

Order

It is not about the protocol!

Checkout Payment Inventory Shipment

Order placed Retrieve payment

It can still be messaging!

@berndruecker

slide-83
SLIDE 83

Order

It is about where to decide about the coupling!

Checkout Payment Inventory Shipment

Order placed Retrieve payment

Order decides . to listen to the event . to issue the command

@berndruecker

slide-84
SLIDE 84

Extract Orchestration logic

slide-85
SLIDE 85

Workflows live inside service boundaries

@berndruecker

slide-86
SLIDE 86

Your IT architecture

Choreography Orchestration

@berndruecker

Your services

  • r applications
slide-87
SLIDE 87

Monolith Chaos Choreography Orchestration

@berndruecker

Process Monitoring

Your services

  • r applications
slide-88
SLIDE 88

Your IT architecture

Process Monitoring

Monolith Chaos Choreography Orchestration

Your services

  • r applications

Balance choreography and orchestration

@berndruecker

slide-89
SLIDE 89

. Distributed systems are complex. At-least-once, retries and idempotency are here to stay. Embrace async! . Long-running services make your life easier and your API smarter. . Change business processes and customer experience accordingly . Use commands + events = balance choreography and

  • rchestration
slide-90
SLIDE 90

Thank you!

slide-91
SLIDE 91

mail@berndruecker.io @berndruecker https://berndruecker.io https://medium.com/berndruecker https://github.com/berndruecker

https://www.infoq.com/articles/events- workflow-automation

Contact: Slides: Blog: Code:

https://www.infoworld.com/article/3254777/ application-development/ 3-common-pitfalls-of-microservices- integrationand-how-to-avoid-them.html https://thenewstack.io/5-workflow-automation- use-cases-you-might-not-have-considered/