You’re scaling your app too early

Swizec Teller
6 min readFeb 26, 2018

--

This app is gonna hit it big for sure! I better code for scale. Never gets past 100 users.

NOTE: This is a cross-post from my newsletter. I publish each email two weeks after it’s sent. Subscribe to get more content like this earlier right in your inbox! 💌

This is such an important part of the system, I better make it flexible! Select all, delete; a week later.

Oh I repeated myself, maybe I can add an abstraction and pass in a prop that tells my component what to do exactly and then I can … spend the rest of my life explaining how it works.

Some of my worst code has come 👇

  • When solving problems I didn’t have and thought I would
  • Building stuff I didn’t know smarter people solved already

building stuff smarter people already solved

When I was 12 or 13, I built a huge app. This was in DOS still. It did many things.

Because it did many things, it had to remember a lot of things. I knew how to use GOTO, but I didn't know about functions. So everything was in global scope.

I used a, then b, and eventually z. I was out of variables. So I created aa, ab and so on.

Then somebody told me about arrays and objects.

Oh you think that’s silly?

When was the last time you implemented a queue? Or a virtualized list of some sort. Or something else entirely.

Sure the left_pad incident was funny, but there’s a world of problems we think are easy to solve that aren’t. The creator of django-registration, an authentication framework for a popular backend, just published an article about usernames.

Did you know usernames were so hard? I didn’t. Have you implemented username handling before? I sure have, many times.

Yes even when you say “Oh let’s just use phone numbers”. That’s a username.

Solving problems you don’t have

As engineers we like to solve problems.

The only thing we like more than solving problems is imagining future problems and solving those.

People sometimes come to me and say “My app is getting crazy popular, we have like 100 requests per minute. That’s a lot. We should start using a fast in-memory database and NoSQL and add a bunch of RabbitMQ jobs and our data has like two thousand rows already so we need Hadoop right”

Nah, you’re good.

And even that’s nothing. A monolithic rails server can handle 20reqs/second or more depending on what those requests are doing. Sure you’re eventually going to move processing into background jobs, you might need a beefier database, you add another server or two, or rent bigger servers.

Computers are fast my dude. Very fast.

And system are weird. Very hard to think about. The more you engineer for scale, the harder they get to think about.

And you know what that means, don’t you? It means you have no idea how your system is going to break. Even if you think you do, and there are some patterns you learn with experience, you still don’t.

Your system will surprise you. Your system will break in a way you didn’t anticipate. Your system will have a bottleneck you didn’t think of. The bottleneck you thought you had will work perfectly. Then suddenly it won’t.

I took a systems modeling class in college. Called stochastic modeling. That shit was hard. When you’re dealing with multiple stochastic processes talking to each other all hell breaks loose.

A stochastic process is a process that is governed by randomness. You can calculate the distribution of your random function, but you can’t predict exactly when something will happen.

On any given minute 10 people might visit your site, or 100. Probably not 1000. The most likely number is 30. The highest you’ve seen is 200. The long tail is long and still at some 20% probabilty around 100.

Oh and the distribution shape changes throughout the day.

Now multiply this over every background worker and every user and every interaction your user performs on your site and …

But the good news is computers are fast. You can get away with a lot. We have a timeseries table in Postgres with 8,000,000 rows. It’s slow to query but it works great 👌 if you stick to indexed fields in indexed ways.

Writes fast, too.

And someone will read this and laugh at me for thinking 8,000,000 is a lot. People do crazy things out there. Just read the replies to my tweet

Look at Epic Games, 3.4 MILLION concurrent users. That’s users at the same time.

They had a bit of a slow down as a result. Then they apologized.

Bonkers.

The correct response to “How do I scale my app?” is to wait and see and monitor. Your app will tell you where it hurts. Listen. Then fix.

Same is true on frontend. Your team members will complain about your code. Then you fix it.

Impossible to predict what’s going to be hard to use 6 months from now :)

In other news…

I finally met my long-time editor Will Fanguy in person! We suck at taking pictures, but here we are eating Japanese hot pot in the Sunset.

He made me go aaaaaall the way out there for dinner. Worth it.

I also published an article about D3. It’s been a while.

3 key insights that make D3.js easy to learn

It’s a good one. I like it. You should read it, if you’re interested in having that a-ha moment with D3 and haven’t read my book yet.

And I wrote about the sidehustle. 2018 is off to a rocky start.

Because too few people write about things when they’re not going so well. One of my least parts of the internet. Everyone’s always so perfect. Pah!

A few cool things

The absolutely coolest thing on the internet is this climbing wall pong game. Climb the wall, play pong. Amazing.

I also enjoyed the idea of Rekit, a proper React IDE. Haven’t had a chance to use it yet, doing that soon.

There’s also this Frontend Interview Handbook with a list of questions and answers for frontend interviews. I’m not sure how I feel about it because I think interviews should be about how you think and solve problems, not how much stuff you can memorize.

But I’m biased because I always did poorly in memory-based tests. There’s a reason I never graduated college ;)

And I really really need to start using Gatsby for my blog so I can put React components into Markdown because that’s just cool.

Seen anything cool lately? Fun stories to share? Just wanna say hi 👋 ? Leave a comment!

Cheers,

~Swizec

P.S. If you like this, make sure to subscribe, follow me on twitter, buy me lunch, and share this with your friends 😀

Also, retweeting this is a great way to share this with your friends:

This story is published in Noteworthy, where 10,000+ readers come every day to learn about the people & ideas shaping the products we love.

Follow our publication to see more product & design stories featured by the Journal team.

--

--

Swizec Teller

A geek with a hat, author of Why programmers work at night, React+D3v4 and others