Slide 1

Slide 1 text

Andrew Godwin @andrewgodwin

Slide 2

Slide 2 text

Andrew Godwin Hi, I'm Django core developer Senior Software Engineer at Apparently now does software architecture

Slide 3

Slide 3 text

The Monolith

Slide 4

Slide 4 text

The Monolith Only one version of any dependency Everything can import everything Deployed all at once No separation Side-effects from other code

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Services Code split up by purpose/team Defined cross-boundary API Deployed separately Can use different versions of dependencies Isolated from each other

Slide 7

Slide 7 text

Why services?

Slide 8

Slide 8 text

Easier to manage Smaller, self-contained problems

Slide 9

Slide 9 text

Independent Scaling And easier performance analysis

Slide 10

Slide 10 text

Faster Individual Deployment Less to deploy at once

Slide 11

Slide 11 text

Complex Interdependencies Harder to deploy & track bugs

Slide 12

Slide 12 text

Requires great communication Teams need calling contracts and APIs

Slide 13

Slide 13 text

More points of failure Not just one set of homogenous servers

Slide 14

Slide 14 text

No more quick hacks Separation forces a level of code design

Slide 15

Slide 15 text

Switching To Services Or: How I Learned To Stop Worrying And Love The Monolith

Slide 16

Slide 16 text

Identify the "cut points" You might need to make some

Slide 17

Slide 17 text

Allocate inventory Calculate Price & Charge card Finalise order Make Order Row &

Slide 18

Slide 18 text

Make Order Row Allocate inventory Calculate Price Charge card Finalise inventory Finalise order

Slide 19

Slide 19 text

Make Order Row Allocate inventory Calculate Price Charge card Finalise inventory Finalise order

Slide 20

Slide 20 text

Define APIs between services Behave like all other teams are third-party

Slide 21

Slide 21 text

Separate Datastores & Servers Make them as separate as possible

Slide 22

Slide 22 text

Communication & Transport

Slide 23

Slide 23 text

Service 2 Service 3 Service 1

Slide 24

Slide 24 text

Service 2 Service 3 Service 1 Direct Communication (20 services? 190 connections!)

Slide 25

Slide 25 text

Service 2 Service 3 Service 1 Direct with discovery Orchestrator

Slide 26

Slide 26 text

Service 2 Service 3 Service 1 Centralised Routing Router

Slide 27

Slide 27 text

Service 2 Service 3 Service 1 Message Bus

Slide 28

Slide 28 text

Centralised Comms Tradeoffs Distributed Comms Single point of failure Nasty partial failures

Slide 29

Slide 29 text

At-least-once delivery Tradeoffs At-most-once delivery Some messages duplicated Some messages lost

Slide 30

Slide 30 text

First-In-First-Out Tradeoffs First-In-Last-Out Easily backlogged Wide range of latencies

Slide 31

Slide 31 text

Channels & ASGI

Slide 32

Slide 32 text

Channel Layer Interface Server Worker Server Process 1 ASGI ASGI Asynchronous socket handling Synchronous Django project Interface Server Worker Server ASGI ASGI Worker Server ASGI Process 2 Process 3 Process 4

Slide 33

Slide 33 text

Service 2 Service 3 Service 1 Channel Layer

Slide 34

Slide 34 text

Service Client inventory.request response.aF53Vds21

Slide 35

Slide 35 text

At-most-once delivery ASGI's Tradeoffs You have to design for potential loss Low-latency but non-persistent Good for protocols, bad for important task queues Capacity, Backpressure and FIFO Informs producers quickly about pileups in the queue

Slide 36

Slide 36 text

Top Service-Oriented Architecture Tips

Slide 37

Slide 37 text

Per-request "correlation IDs" Track a set of service calls through the stack

Slide 38

Slide 38 text

Feature Flag message headers Bundle them in, don't have every service query them

Slide 39

Slide 39 text

Source Of Truth Each data model has a service that owns (& caches) it

Slide 40

Slide 40 text

Metrics. Metrics everywhere. Both performance and network health

Slide 41

Slide 41 text

Design for failure Don't assume two things will both succeed

Slide 42

Slide 42 text

DO NOT START OFF WITH SERVICES Write separate Python libraries instead

Slide 43

Slide 43 text

Thanks. Andrew Godwin @andrewgodwin