Slide 1

Slide 1 text

Lessons from 6 months of using Luigi in production @peterowlett @deliveroo

Slide 2

Slide 2 text

Hello! I’m Pete

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

I work for these folks

Slide 5

Slide 5 text

WE DO THIS

Slide 6

Slide 6 text

Why it’s better to be woken up by your cat than by the server alarm A BETTER TITLE

Slide 7

Slide 7 text

This is Kitty

Slide 8

Slide 8 text

NO RESPECT FOR PERSONAL SPACE

Slide 9

Slide 9 text

This is PagerDuty

Slide 10

Slide 10 text

Even less respect for personal space

Slide 11

Slide 11 text

Let’s Compare! - Goes off at any time, day or night - Loud ring tone, text messages, answer phone messages and flashing - Resolution can take hours - Goes off only once at precisely 6am - Cute batting motion to wake - Resolved in time it takes to open cat food packet

Slide 12

Slide 12 text

I think we can all agree with my premise Kitty >> PagerDuty

Slide 13

Slide 13 text

Lets get to it

Slide 14

Slide 14 text

Chapter 1 “The Model”

Slide 15

Slide 15 text

Let’s build a model

Slide 16

Slide 16 text

I’m ready, where’s the data?

Slide 17

Slide 17 text

“Just pg_dump the prod db”

Slide 18

Slide 18 text

OH PLS PLS NO DON’T DO THAT

Slide 19

Slide 19 text

Lets spin up a read slave and ETL the data to a warehouse …

Slide 20

Slide 20 text

… then train our models from that

Slide 21

Slide 21 text

How do we ensure tasks run in Order?

Slide 22

Slide 22 text

I want them to run one after the other 2 1 3 4 5 6 7 8

Slide 23

Slide 23 text

Directed Acyclic Graph

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

Enter Stage Left …

Slide 26

Slide 26 text

Simple Task

Slide 27

Slide 27 text

Postgres Loader Task

Slide 28

Slide 28 text

We string these together to make DAGs CHECK MAX ROW ID LOAD DATA MOD DATA MAKE MODEL CHECK MAX ROW ID LOAD DATA TABLE1 TABLE2

Slide 29

Slide 29 text

DAGs solve the dependency problem

Slide 30

Slide 30 text

Bung it all on EC2

Slide 31

Slide 31 text

Define an entry point

Slide 32

Slide 32 text

Run the scheduler

Slide 33

Slide 33 text

Kick it all off with CRON

Slide 34

Slide 34 text

With luigi we were up and running in a few hours

Slide 35

Slide 35 text

Chapter 2 “The Nuclear Option”

Slide 36

Slide 36 text

A few weeks later, something happened …

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Schema can change anytime without warning HAS THE SCHEMA CHANGED? RELOAD JUST NEW ROWS DROP AND CREATE WHOLE SCHEMA RELOAD ALL TABLES NO! YES!

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Handle schema changes robustly

Slide 41

Slide 41 text

Let’s test our pipeline before we deploy it. But how?

Slide 42

Slide 42 text

Two new operating modes TEST MODE Run the whole pipeline but only write to a test schema UNIT MODE Run the current task, ignoring its dependencies

Slide 43

Slide 43 text

Configure these modes in the pipeline using luigi.Parameter

Slide 44

Slide 44 text

Now nothing will ever go wrong, ever again …

Slide 45

Slide 45 text

Make your testing comprehensive

Slide 46

Slide 46 text

Make your testing fast

Slide 47

Slide 47 text

Adding in external API services

Slide 48

Slide 48 text

Build Loaders for each API

Slide 49

Slide 49 text

Loading Schedules

Slide 50

Slide 50 text

Plumbing them in

Slide 51

Slide 51 text

Keep def rows as short as possible

Slide 52

Slide 52 text

Be consistent in loader design pattern

Slide 53

Slide 53 text

Expect external API services to misbehave

Slide 54

Slide 54 text

Expect external API services to misbehave X

Slide 55

Slide 55 text

Trust external API services as if they actively want to hurt you

Slide 56

Slide 56 text

Hey cool, all our data is in one place, we might as well use it for BI Reporting

Slide 57

Slide 57 text

Chapter 3 “The Management Report”

Slide 58

Slide 58 text

This happened

Slide 59

Slide 59 text

And then your ad hoc database is now supporting global business critical apps

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

Stuff that was happening • Irrelevant upstream failures • Low priority upstream failures • Flakey Data (but it worked!)

Slide 62

Slide 62 text

Our DAG looked like this: START LOAD2 LOAD1 LOAD3 LOAD DONE MAKE1 MAKE2 MAKE3 END

Slide 63

Slide 63 text

And this was happening START LOAD2 LOAD1 LOAD3 LOAD DONE MAKE1 MAKE2 MAKE3 END

Slide 64

Slide 64 text

This one doesn’t need LOAD3 START LOAD2 LOAD1 LOAD3 LOAD DONE MAKE1 MAKE2 MAKE3 END

Slide 65

Slide 65 text

So we changed it to this START LOAD2 LOAD1 LOAD3 LOAD ALL MAKE1 MAKE2 MAKE3 END

Slide 66

Slide 66 text

Now when 3 fails: START LOAD2 LOAD1 LOAD3 LOAD ALL MAKE1 MAKE2 MAKE3 END

Slide 67

Slide 67 text

Decide about what can be allowed to fail, and what can’t

Slide 68

Slide 68 text

Isolate the path to critical ops jobs

Slide 69

Slide 69 text

Loading tables more reliably 5AM SATURDAY

Slide 70

Slide 70 text

The currency table failed to update

Slide 71

Slide 71 text

Loading tables more reliably DROP TABLE CREATE TABLE LOAD DATA Task 1 Task 2 Task 3

Slide 72

Slide 72 text

Loading tables more reliably DROP TABLE CREATE TABLE THIS CAN GO WRONG LOAD DATA Task 1 Task 2 Task 3 THIS CAN GO WRONG THIS CAN GO WRONG

Slide 73

Slide 73 text

Expect Failure, Rollback Transaction CREATE TEMP TABLE Task 1 (There is no task 2) LOAD DATA RENAME OLD TABLE RENAME NEW TABLE ROLLBACK

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

Encapsulate logic in bigger chunks

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Anticipating problems early

Slide 78

Slide 78 text

Going beyond system monitoring

Slide 79

Slide 79 text

Defined Monitoring Tests

Slide 80

Slide 80 text

Measuring outcomes directly

Slide 81

Slide 81 text

And get gentler alerts in slack

Slide 82

Slide 82 text

Monitor (and alert on) outcomes as well as system metrics

Slide 83

Slide 83 text

Try / Except / Slack Alert low priority tasks

Slide 84

Slide 84 text

Chapter 4 “Hi, this is Australia calling …”

Slide 85

Slide 85 text

In the beginning there was the UK YAY! DOWNTIME!! Midnight Midnight Midday UK Ops

Slide 86

Slide 86 text

Then Europe Ok cool still loads of downtime Midnight Midnight Midday

Slide 87

Slide 87 text

Then Some Other Places No such thing as downtime anymore Midnight Midnight Midday

Slide 88

Slide 88 text

Table Loading - Take 2 HASH THE TABLE SCHEMA COMPARE TO LAST HASH SAME! CHANGED! DROP AND REBUILD JUST LOAD ROWS

Slide 89

Slide 89 text

Get rid of the nuclear option

Slide 90

Slide 90 text

SORRY RIPLEY

Slide 91

Slide 91 text

Chapter 5 “Moving to Scale”

Slide 92

Slide 92 text

When it comes to BI, Old School Rules Still Apply

Slide 93

Slide 93 text

Configuration Management (Docker + ECS)

Slide 94

Slide 94 text

Distributed workers make some pain go away

Slide 95

Slide 95 text

Protobuf3 on Message Bus

Slide 96

Slide 96 text

Final Thoughts

Slide 97

Slide 97 text

I regret nothing!

Slide 98

Slide 98 text

Everything is defined in code

Slide 99

Slide 99 text

Two people, tiny budget

Slide 100

Slide 100 text

Time spent speeding up the build process is time well spent

Slide 101

Slide 101 text

Think carefully about what dependencies *mean*

Slide 102

Slide 102 text

To finish …

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

We’re hiring! Grab me after :) https://roo.it/peteo Also £5 off your first order!

Slide 105

Slide 105 text

Sleep Well! @peterowlett @deliveroo Sleep Well!