DEV Community

Tyler Smith
Tyler Smith

Posted on • Updated on

"But does it scale?" A pragmatic overview of infrastructure scalability

Software development is a massive subject, so it's normal to search for information on a wide variety of blogs, Reddit, and Hacker News threads. Inevitably, at some point you'll run into the "but does it scale?" comment, followed by recommendations for technologies that "scale better."

Suddenly, you're worried that you may be learning the wrong technology, and go down a rabbit hole researching the "more scalable" recommendations. Before you know it, you've lost a week to reading about different technologies and you haven't written a single line of code.

What is scalability?

Scalability can refer to a lot of different things in software, but in almost all instances it means you can add more of something without the system breaking. Scalable software design is software that is architected to allow you to add more code without significantly increasing the complexity required to maintain it. Scalable processes are processes that won't break when you add additional team members.

For this post, we will focus on the ability for an application to scale to handle additional traffic and users.

Does Rails/Laravel/Etc. scale? Yes.

As you stumble across the Internet from blog to blog, you will inevitably come across performance tests that tell you how many requests-per-second your framework or language can handle. This is usually the point where panic sets in.

"Oh no! According to this blog post, PHP can only handle 1,600 requests per second, but Java can handle 5 million per second! I need to quit PHP immediately and learn Java."

I have good news: there's no need to panic. It's understandable to worry that you're going down the wrong road, and that if your app gets popular you'll have to rewrite it in a different language. But the famously-slow language PHP powers over 75% of the sites on the Internet, including a good portion of Facebook.

How do apps scale?

When you read about the performance characteristics of a language like PHP, it seems impossible that it could power so much of the Internet. So how can PHP and other "slow" languages scale? They use a wide assortment of techniques and tools that help distribute the responsibility of one app across several systems.

Cache is an easy-to-access copy of data that you may need again. Imagine your friend has a great chocolate chip cookie recipe. It would be time-consuming to go to their house every time you wanted to look at the recipe, so you make a copy of the recipe to keep at your home.

Cache works the same way: you can tell a browser to cache individual pages and files so it doesn't have to repeatedly go to the server to get the same resources. You can cache almost anything: rendered HTML, database queries, images, etc. Caching is one of the most powerful tools available for scaling performance.

Content Delivery Networks (also known as CDNs) are ultra-high performance caching services that can sit in front of your website and return responses to the browser without ever having to talk to your server. It's not uncommon for a CDN to handle over 90% of your traffic without ever hitting the server.

Load balancers are tools that let you split your traffic across multiple servers that each host a copy of your application. By adding another server, you can theoretically double the amount of traffic your application can handle.

One thing to note when you use load balancers: you'll need to move your database to its own server, otherwise the data won't be consistent across your application servers.

Sharding is a technique for breaking up the data in a large database across multiple servers.

Managed services are paid services that can automatically scale your app for you. Services like Cloudflare offer-out-of-the-box CDNs. Heroku is a hosting service that will automatically create new servers and configure a load balancer when you get more traffic. Managed services are the simplest way to scale apps to handle more traffic with the least amount of effort.

When should you worry about scalability?

I'm going to offer you the advice that I wish I had gotten in my first two years as a developer:

Don't worry about scaling until after you've written your app.

It is easy to lose weeks worrying about scalability issues you may never experience. Unless you're building an app that you can be certain will have millions of users at launch (think healthcare.gov), it's better to focus on building a great experience first and maintaining your ability to move quickly.

Worrying about scalability too early will add complexity that can slow you down. Even with platforms like Cloudflare and Heroku that can offer easy wins, you can run into some technical challenges that are hard to work through if you aren't familiar with the platform. By focusing on completing your app first, you can incorporate feedback sooner and build the app your users want.

Parting thoughts

There's only one thing I want you to take away from this post: regardless of the technology you build your application with, it's almost certainly possible to scale it to handle any amount of traffic you'll get. Go build something cool.

Discussion (1)

Collapse
tanzimibthesam profile image
Tanzim Ibthesam

In case of apps with hugher budget and that will reach mass people scalability performance might be an issue at first. But 90% of the cases its about getting the job done shipping v1 of the product