Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation...

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

Transcript of Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation...

Page 1: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

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

@berndruecker

Page 2: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot
Page 3: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

SomeService

Failure will happen. Accept it!

But keep it local! Be resilient.

Page 4: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

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

Page 5: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

„There was an errorwhile sending your

boarding pass“

Page 6: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Web-UI

Me

Current situation

Page 7: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 8: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation

Page 9: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the good part

Circuit breaker

Page 10: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot
Page 11: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Page 12: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

Page 13: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Current situation – the bad part

StatefulRetry

Page 14: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot
Page 15: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

We are having some technicaldifficulties and cannot present you

your boarding pass right away.

But we do actively retry ourselves, so lean back, relax and we will send it

on time.

Page 16: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

Page 17: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Possible situation – much better!

StatefulRetry

Page 18: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Warning:Contains Opinion

Page 19: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Berlin, Germany

http://berndruecker.io/[email protected]@berndruecker

Bernd RueckerCo-founder and Chief Technologist ofCamunda

Page 20: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-In

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

BarcodeREST

Statefulretry

Page 21: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Want to see code?https://github.com/berndruecker/flowing-retail

Page 22: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

has to implement

Retryhas to implement

Idempotency

Client Service Provider

Page 23: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot
Page 24: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot
Page 25: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Don‘t worry, it will happen safely –even if you loose connection.

Feel free to reload this page any time!

Page 27: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Requirement: Idempotency of services!

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

Page 28: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Requirement: Idempotency of services!

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

Page 29: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Make every service idempotent!

CreditCard

Payment

Charge Credit CardcardNumber

amount

Charge Credit CardcardNumber

amounttransactionId

Not idempotent

Idempotent

charge

Generally: create Idsas soon as possible

Page 30: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Page 31: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Distributedsystems

Page 32: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

It is impossible todifferentiate certain

failure scenarios.

Independant ofcommunication style!

Service Provider

Client

Page 33: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Page 34: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Distributed systems introduce complexity you have to tackle!

CreditCard

PaymentREST

Cancel

charge

Page 35: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Being able to implementlong running services

is essential for smart APIs(on a technical level)

@berndruecker

Page 36: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Booking Payment

RetrievePayment

@berndruecker

Page 37: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Booking PaymentCreditCard

RetrievePayment

@berndruecker

Page 38: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Booking PaymentCreditCard

RetrievePayment

Rejected

@berndruecker

Page 39: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Booking Payment

If the creditcard was

rejected, thecustomer canprovide new

details

CreditCard

RetrievePayment

RejectedRejected

@berndruecker

Page 40: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Booking Payment

If the creditcard was

rejected, thecustomer canprovide new

details

CreditCard

RetrievePayment

RejectedRejected

@berndruecker

A fewsmart god services tellanemic CRUD services what to do

Sam Newmann

Page 41: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Paymentfailed

Who is responsible to deal with problems?

Booking Payment

If the credit card was

rejected, the customer can provide new

details

CreditCard

RetrievePayment

RejectedPaymentreceived

@berndruecker

Page 42: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Paymentfailed

Long running services

Booking PaymentCreditCard

RetrievePayment

RejectedPaymentreceived

Smart endpoints are potentially long-running

@berndruecker

Page 43: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Being able to implementlong running services

is essential for smart APIs(on a business level)

@berndruecker

Page 44: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Long running servicesrequire async communication

Page 45: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Synchronous communication

Page 46: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Synchronous communicationis the crystal meth of

distributed programming

Todd Montgomery and Martin Thompson in “How did we end up here” at GOTO Chicago 2015

Page 47: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Check-in

Barcode Generator

Web-UI

Me

Output Mgmt

Asynchronous communication

You need tomonitor timeouts

Page 48: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Workflow…

Page 49: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Workflow…

Page 50: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Being able to implementlong running services

makes it easy to get async

@berndruecker

Page 51: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Can your companyleverage yourhipster architecture?

Sh

utte

rstock

You need tochange businessprocesses andcustomerexperience!

Page 52: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

@berndruecker

Page 53: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

Payment

SeatReservationBooking

TicketGeneration

Page 54: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

@berndruecker

sync

Page 55: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example

@berndruecker

Page 56: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Weaknesses

Payment

SeatReservationBooking

TicketGeneration

REST

Page 57: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Weaknesses: Latency creep

Payment

SeatReservationBooking

TicketGeneration

REST

300 ms1150 + x ms

600 ms

250 ms

Page 58: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Weaknesses: Availabiliy erosion

Payment

SeatReservationBooking

TicketGeneration

REST99 % uptime

99 % uptime

99 % uptime

96 % uptime

Page 59: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

And it is even hard to implement

Payment

SeatReservationBooking

TicketGeneration

REST

Page 60: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

And it is even hard to implement

Payment

SeatReservationBooking

TicketGeneration

REST

Page 61: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Typical pattern

Payment

SeatReservationBooking

TicketGeneration

REST

Simulate synchronicty by waiting(callback or polling)

Page 62: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

@berndruecker

happy case

failurecase

Redesign your business process accordingly!

Or some interfaceto poll for status

Sync in happy case

Async response

Page 63: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

@berndruecker

Redesign your business process accordingly!

Page 64: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Your business processes need to be more reactive!

@berndruecker

https://www.reactivemanifesto.org/

Page 65: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Yeah!Let‘s go reactive.

Page 66: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Phil Calcado at QCon NYC 2019

Page 67: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

API

API

APIAPI

API

API

API

Microservices

External Services

Standard Software

„What the hell just happened?“

@berndruecker

Page 68: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Example:order fulfillment viadash button

Photo by 0xF2, available under Creative Commons BY-ND 2.0 license. https://www.flickr.com/photos/0xf2/29873149904/

@berndruecker

Page 69: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Three steps…@berndruecker

Page 70: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

(Micro-)services

Checkout

Payment

Inventory

Shipment

@berndruecker

Page 71: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

OrderPlaced

PaymentReceived

GoodsFetched

Notification

Checkout

Payment

Inventory

Shipment

Event-driven architecture@berndruecker

Page 72: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Peer-to-peer event chains

Checkout

Payment

Inventory

Shipment

Order placed

Payment received

Goodsshipped

Goodsfetched

@berndruecker

Page 73: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Peer-to-peer event chains

Checkout

Payment

Inventory

Shipment

Order placed

Payment received

Goodsshipped

Goodsfetched

@berndruecker

Page 74: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

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

Page 75: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

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

Page 76: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

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

Page 77: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Peer-to-peer event chains

Checkout

Payment

Inventory

Shipment

Order placed

Payment received

Goodsshipped

Goodsfetched

Fetch the goodsbefore thepayment

@berndruecker

Page 78: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Peer-to-peer event chains

Checkout

Payment

Inventory

Shipment

Fetch the goodsbefore thepayment

Goodsfetched

Order placed

Payment received

Goodsshipped

@berndruecker

Page 80: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Order

Extract the end-to-end responsibility

Checkout

Payment

Inventory

ShipmentPaymentreceived

Order placed

Retrievepayment

@berndruecker

Page 81: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Order

Events & Commands

Checkout

Payment

Inventory

ShipmentPaymentreceived

Order placed

Retrievepayment

@berndruecker

Event

Command

Fact, happened in the past, immutable

Intend, Want s.th. to happen

Page 82: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Order

It is not about the protocol!

Checkout

Payment

Inventory

Shipment

Order placed

Retrievepayment

It can still be messaging!

@berndruecker

Page 83: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Order

It is about where to decide about the coupling!

Checkout

Payment

Inventory

Shipment

Order placed

Retrievepayment

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

@berndruecker

Page 84: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Extract Orchestration logic

Page 85: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Workflows live inside service boundaries@berndruecker

Page 86: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Your IT architecture

Choreography

Orchestration

@berndruecker

Your servicesor applications

Page 87: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Monolith Chaos

Choreography

Orchestration

@berndruecker

Process Monitoring

Your servicesor applications

Page 88: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Your IT architecture

Process Monitoring

Monolith Chaos

Choreography

Orchestration

Your servicesor applications

Balance choreography and orchestration@berndruecker

Page 89: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

. 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 orchestration

Page 90: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

Thank you!

Page 91: Moving beyond request-reply: How smart APIs are different....Web-UI Me Output Mgmt Current situation –the bad part Stateful Retry. We are having some technical difficulties and cannot

[email protected]@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/