34
Die Another Day Scaling from 0 to 4M requests per day as a lone developer

Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

  • Upload
    itnig

  • View
    855

  • Download
    0

Embed Size (px)

DESCRIPTION

Scaling an app includes many different skills: from writing good code to system administration and architecture. This are the slides of Cristian Planas talk, that took place at itnig on February 20th. Cristian is co-founder & CTO at Playfulbet, and he explained some basic lessons taken from the case of Playfulbet, a social game with more than 150.000 registered users.

Citation preview

Page 1: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Die Another Day

Scaling from 0 to 4M requests per

day as a lone developer

Page 2: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

I am Cristian…

Gawyn

@crplanas

Page 3: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

… and this is the story of how Playfulbet is

growing.

Page 4: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The growth of Playfulbet is not so

spectacular.

1.5M daily pageviews4M daily requests

Page 5: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

But the interesting part of this story is the small

resources we had.

This is not only the story of how Playfulbet grows, but how I grow.

Page 6: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Me, scaling in October 2012

Page 7: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Me, scaling in February 2014

Page 8: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The difference?

One week of October 2012 v.

One week of February 2014

Page 9: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

We are going to talk about different

techniques for scaling.

Page 10: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

But first, we need to understand how an app

works.

Page 11: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The Restaurant

Analogy

Page 12: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Requests = CustomersWaiters = Application

instancesFood = Data

Page 13: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

So you want to scale your application?

Meet your next best friend:

Page 14: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The application graph

Page 15: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The browser graph

Page 16: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

What happens when something goes wrong

Page 17: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

There are 2 ways for improving load time:

1. Improve app performance

2. Improve your architecture

Page 18: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Improving performance

Page 19: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The basic basics

-Use indexes in your DB.-Optimize your queries: eager loading, pluck….

Page 20: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Cache

In Playfulbet we use memcached.

Page 21: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Materialize

Use the DB –or another resource- to create a

shortcut to the data you need.

Page 22: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

An example

A bet is made on an option.An option exists on a market.A market exists on an event.

An event exists on a competition.A competition exists on a sport.

All the bets should show an icon depending of the sport.

Page 23: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Fake if it’s necessary.

The accuracy of some data is critical.

But the accuracy of all data is not always critical.

Page 24: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Improving the architecture

Page 25: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

In the beginning there was only one server.

His name is…

Page 26: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

But the load was too heavy.

So Maradona needed some help in the back.

Page 27: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Obviously, our staging server also has a cool name.

Page 28: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

At this point we decided to move our

DB to Amazon.

Good: You don’t need to manage it yourself.

Bad: Latency.

Page 29: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

The structure kept growing.

Page 30: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Our current structureProxy

ChatSSL

Memcached

25 “Frontal” servers

3 “Back” serversRedis

Page 31: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

But this structure can’t continue.

1. Our DB has performance problems.

2. There are cheaper alternatives.

3. VPS don’t scale CPU.

Page 32: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

In the very near future:

1. We are moving to dedicated servers.

2. We will use slave DBs for reads.

3. We will have someone in charge of the system

administration.

Page 33: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

So this is the end of me as the only technical

guy in Playfulbet.

And this is why I wanted to share this

story with you.

Page 34: Die Another Day: Scaling from 0 to 4 million daily requests as a lone developer by Cristian Planas

Thanks!