Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3...

69
Containerizing your monolith Jano González (@janogonzalez)

Transcript of Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3...

Page 1: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Containerizing your monolith

Jano González (@janogonzalez)

Page 2: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Introduction

Page 3: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

What’s SoundCloud

Page 4: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

> 200M Tracks > 20M Creators Many SoundCloud Rappers

What’s SoundCloud

Page 5: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

2017-2018 Migration Keep moving

Motivation

Page 6: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

What’s the balance?

Motivation

Page 7: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Our migration to microservices

The monolith

Containerizing the monolith

Conclusion

Contents

Page 8: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Our migration to microservices

Page 9: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

$ rails new soundcloud

How we started

Page 10: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Around 2012

Page 11: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Around 2012

Page 12: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Around 2012

Page 13: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Around 2012

Page 14: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

After

Page 15: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

After

Page 16: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

But what about deployment?

Page 17: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Component Environment Zone

DeploymentOur abstractions

Page 18: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

DeploymentThe process

Page 19: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The monolith

Page 20: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Track User Playlist

The monolithCore entities

Page 21: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

360 Chef provisioned bare-metal machines

Rails 2.3 Capistrano deployment

The monolithThe technology

Page 22: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The monolithThe architecture

Public API

Internal API

Public API Strangler

Internal API caching/strangler

Another BFF

Many microservices

Public Web

Workers

Page 23: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The monolithThe components

Public API

MoshiMoshi (Internal API)

Public Web Assets

MoshiMoshi Comments

(Internal API)

Workers Cron Shell Migration

Page 24: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The monolithThe hosts

component

statsd-exporter

mtail statsd

passenger-exporter …

Page 25: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Utilization Deployment Lack of confidence

The monolithThe issues

Page 26: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Containerizing the monolith

Page 27: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Throw it into Kubernetes

Page 28: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Congrats, your monolith is a microservice now

Page 29: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Thank You!

Page 30: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

1.5 Engineers 1 year until the last bit was cleaned up

The project

Page 31: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The first milestone

Page 32: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Docker development container

Tests on GoCD

The first milestone

Page 33: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The proof of concept

Page 34: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

First staging component

The proof of conceptDoes it even work?

Page 35: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The proof of conceptPROBLEM!

Init script Nginx Passenger Passenger Process Rails App

???

Where are my env variables?

Page 36: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The proof of conceptEnv variables with The Perl Hack™

SOLUTION

Page 37: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing

Page 38: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Deployment Monitoring Logs

ProductionizingDoes it run where it matters?

Page 39: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

ProductionizingAnatomy of a traffic serving pod

component statsd statsd-exporter

passenger-exporter mtail twemproxy

twemproxy-cu twemproxy-exporter init

Page 40: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Don’t choke service discovery

Be allocatable

ProductionizingSizing the pods

Page 41: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

CPU units for main container

Passenger processes

ProductionizingSizing the pods

3 16

Page 42: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

ProductionizingPROBLEM!

Stdout v/s the log metrics exporter

Component

STDOUT

Log aggregator

File???

Mtail

Page 43: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

ProductionizingMtail with The Rotatelogs Hack™

SOLUTION

Page 44: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Public API

Page 45: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Orchestration

Productionizing Public API

Page 46: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Public APIPROBLEM!

DNS latency and our excessive usage

Component

Service Service Service

Page 47: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Public APICoreDNS and the DNS Hack™

SOLUTION

Page 48: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal API

Page 49: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Highest throughput

Productionizing Internal API

Page 50: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIPROBLEM!

Latency was too high

Page 51: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIOptimize GC and make cheaper SQL queries

SOLUTION

Page 52: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIPROBLEM!

Errors spikes during deployment

Page 53: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIThe preStop Trick™

SOLUTION

Page 54: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIPROBLEM!

Errors spikes during deployment (still???)

Page 55: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Productionizing Internal APIThe Pre Start Trick™

SOLUTION

Page 56: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

The rest

Page 57: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

● Workers● Cron jobs● Shell / Migration hosts● Cleanup!

The rest

Page 58: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Finishing

Page 59: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Current status

Page 60: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

On-prem Cloud

Current statusNumber of pods

~1000 ~140

Page 61: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

On-prem RPS Cloud RPS

Current statusTraffic

25K 3K

Page 62: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Current statusMany deploys

Page 63: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Conclusions

Page 64: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

One Infrastructure One Delivery Process

ConclusionsWhat we solved

Page 65: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Step by step Controlled rollouts Managing expectations

ConclusionsHow we did it

Page 66: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Improved utilization Increased confidence Enabling new initiatives

ConclusionsBenefits

Page 67: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Assess current progress Evaluate costs and benefits

ConclusionsShould you do it?

Page 68: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

Thank You!

Page 69: Containerizing your monolith - USENIX · 360 Chef provisioned bare-metal machines Rails 2.3 Capistrano deployment The monolith The technology

@janogonzalez

https://soundcloud.com/janogonzalez