Slide 1

Slide 1 text

Choreography vs Orchestration in serverless microservices Mete Atamel Developer Advocate at Google @meteatamel atamel.dev speakerdeck.com/meteatamel Guillaume Laforge Developer Advocate at Google @glaforge glaforge.appspot.com

Slide 2

Slide 2 text

Choreography vs Orchestration

Slide 3

Slide 3 text

CHOREOGRAPHY ORCHESTRATION

Slide 4

Slide 4 text

Imagine a simple e-commerce transaction Services calling each other directly Frontend App Engine Order request Payment Processor Cloud Run Authorize & charge CC Shipper Cloud Functions Prepare & ship items Notifier Cloud Run Notify user

Slide 5

Slide 5 text

Simple REST: Pros and Cons Pros ➕ Better than a single monolith ➕ Easy to implement: Services simply call each other Cons ➖ Too much coupling between all the services ➖ Each service can be a SPOF ➖ Each service needs its own error / retry / timeout logic ➖ Who ensures the whole transaction is successful?

Slide 6

Slide 6 text

Choreography (event-driven) Event-driven services Frontend App Engine Order request Payment Processor Cloud Run Authorize & charge CC Shipper Cloud Functions Prepare & ship items Notifier Cloud Run Notify user Message Broker

Slide 7

Slide 7 text

Imagine a more complex transaction

Slide 8

Slide 8 text

Choreography: Pros and Cons Pros ➕ Services are loosely coupled, ➕ Services can be changed independently ➕ Services can be scaled independently ➕ No single point of failure ➕ Events are useful to extend the system beyond the current domain Cons ➖ Difficult to monitor the whole system ➖ Errors / retries / timeouts are problematic ➖ The business flow is not captured explicitly ➖ Who ensures the whole transaction is successful?

Slide 9

Slide 9 text

Orchestration Orchestrated services Frontend App Engine Order request Payment Processor Cloud Run Authorize & charge CC Shipper Cloud Functions Prepare & ship items Notifier Cloud Run Notify user Orchestrator

Slide 10

Slide 10 text

Orchestration: Pros and Cons Pros ➕ Business flow captured centrally and source controlled ➕ Each step can be monitored ➕ Errors / retries / timeouts are centralized ➕ Use simple REST, no need for events ➕ Services are still independent Cons ➖ A new orchestrator service to worry about ➖ Orchestrator could be a single point of failure ➖ Reliance on REST means more tight-coupling

Slide 11

Slide 11 text

Which one is better? Choreography or Orchestration?

Slide 12

Slide 12 text

It depends... Choreography Services are not closely related Services can exist in different bounded contexts Orchestration Can you describe the business logic in a flow chart? Are services closely related in a bounded context? Do you want to stay in REST?

Slide 13

Slide 13 text

Hybrid approach Orchestrated bounded contexts communicating via events Orchestrated Bounded Context Message Broker Orchestrated Bounded Context Orchestrated Bounded Context

Slide 14

Slide 14 text

Landscape

Slide 15

Slide 15 text

Choreography (event-driven) AWS: SQS, SNS, EventBridge Azure: Event Grid, Event Hubs, Service Bus Google Cloud: Pub/Sub, Eventarc Other: Kafka, Pulsar, Solace PubSub+, RabbitMQ, NATS...

Slide 16

Slide 16 text

Orchestration AWS: Step Functions Azure: Logic Functions Google Cloud: Workflows, Cloud Composer Other: Apache Airflow

Slide 17

Slide 17 text

Serverless Workflow Specification serverlessworkflow.io A sandbox-level project at CNCF for a specification Defines a declarative and domain-specific workflow language for orchestrating events and services

Slide 18

Slide 18 text

Serverless Workflow Specification serverlessworkflow.io Workflow projects need to implement & support the spec Spec doesn’t necessarily cover all aspects of a product and not all products cover the whole specification Services need to be described with OpenAPI

Slide 19

Slide 19 text

Orchestration: Google Cloud Workflows

Slide 20

Slide 20 text

Serverless Compute External API’s Google API’s etc... Workflows - orchestrate & integrate SaaS API’s Private API’s Other Clouds

Slide 21

Slide 21 text

- processPayment: params: [paymentDetails] call: http.post args: url: https://payment-processor.run.app/... body: input: ${paymentDetails} result: processResult - shipItems: call: http.post args: url: https://.../cloudfunctions.net/ship body: input: ${processResult.body} result: shipResult - notifyUser: call: http.post ... Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items YAML or JSON syntax

Slide 22

Slide 22 text

Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items WAIT Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items shipmentDetails userDetails Step Sequencing Serverless Pause Variable passing JSON Parsing Steps

Slide 23

Slide 23 text

Errors and retries Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items MAX: 5 times BACKOFF Payment Processor Cloud Run Authorize & charge CC Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items Pager Cloud Run Escalate to support SUCCESS ERROR Configurable retries Configurable exception handling

Slide 24

Slide 24 text

Conditionals and 3rd party calls Notifier Cloud Run Notify user Shipper Cloud Functions Prepare & ship items Pager Cloud Run Escalate to support SUCCESS ERROR Out of Stock? No Request from the supplier Yes Read inventory Inventory DB Update inventory Inventory DB Supplier API

Slide 25

Slide 25 text

Other useful features Subworkflows to encapsulate common reusable flows Connectors ßeta to connect to other Google Cloud services & APIs

Slide 26

Slide 26 text

Deploy, execute, manage workflows # Deploy a workflow # Execute a workflow # See the result

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

Case study: Pic-a-daily, A microservice-based picture sharing application

Slide 29

Slide 29 text

Pic-a-daily: A photo sharing application g.co/codelabs/serverless-workshop

Slide 30

Slide 30 text

Choreographed (event-driven) architecture

Slide 31

Slide 31 text

3 different event handling approaches

Slide 32

Slide 32 text

Orchestrated architecture

Slide 33

Slide 33 text

Lessons learned

Slide 34

Slide 34 text

Lessons Learned ➕ Simple REST was refreshing (vs. 3 eventing formats) ➕ Less code (eg. no event parsing, no Image Analysis & Garbage Collector functions) ➕ Less setup (eg. no Pub/Sub, no Scheduler, no Eventarc) ➕ Easier error handling (eg. the whole chain stops on error)

Slide 35

Slide 35 text

Lessons Learned ➖ New service to learn with its quirks and limited docs ➖ Code vs. YAML, in a single YAML file (code is easier to write and test than YAML!) ➖ Debugging / testing / logging is not mature, no IDE support ➖ Lost parallelism ➖ Loss of eventing flexibility

Slide 36

Slide 36 text

Cloud Workflows Cloud Workflows tips cloud.google.com/workflows bit.ly/gcw-tips Quickstart cloud.google.com/workflows/docs/quickstarts Codelab: Intro to serverless orchestration with Workflows codelabs.developers.google.com/codelabs/cloud-workflows-intro Thank you Mete Atamel @meteatamel atamel.dev speakerdeck.com/meteatamel Guillaume Laforge @glaforge glaforge.appspot.com