CockroachDB Glossary

Serverless Architecture

At first glance, it sounds impossible – how can any cloud-based architecture be serverless? But of course, the serverless in serverless architecture doesn’t really mean without servers. So what does it mean? Let’s dive in!

What is serverless architecture?

Serverless architecture is an approach to software development that allows developers to ignore considerations associated with the physical machines their code will be run on. Physical machines are still used, of course, but they are provisioned by a cloud provider in accordance with the in-the-moment requirements of the developer’s application.

Serverless architecture thus allows developers to focus on building the services that power their application, without having to worry about which physical hardware to choose, how and when to scale, how and when to maintain and upgrade their machines, etc. Instead, the cloud provider takes care of all of that.

Serverless architectures also typically offer a pay-for-what-you-use model, which is often cheaper than paying for a preset number of dedicated machines. For example, a developer who uploads a function to AWS Lambda will be billed based on how many times the function was run during the billing period.

Examples of serverless architecture

Many elements of an application can now take advantage of serverless architectures.

One of the most common examples of serverless architecture is serverless functions (functions as a service, or FaaS). Cloud providers including AWS (AWS Lambda), Google (Google Cloud Functions), and Microsoft (Azure Functions) allow developers to upload specific application functions to the cloud, where the function will then be run when it is triggered (for example, by an API call).

Another common example is a serverless database such as CockroachDB Serverless. Developers can host a distributed SQL database with the cloud provider of their choice and it will scale automatically (within the developer’s set monthly spending limit) to meet demand.

Serverless architecture and microservices

Serverless architecture is often used in tandem with microservices architecture, as the two complement each other well. When an application is broken down into individual microservices, each of these can be hosted using a serverless architecture, allowing them to auto-scale individually, rather than having to scale all of the application’s resources up and down monolithically.

Why use serverless architecture?

The advantages of using a serverless architecture can vary based on the application, the use case, and the cloud provider, but some of the most commonly-enjoyed benefits are:

  • Scale: Serverless architectures allow applications to scale automatically (from a developer perspective) because all the work and automation associated with scaling is handled by the cloud provider.
  • Cost savings: Because they typically use pay-per-use models (rather than making developers pay for entire machines), they can often offer great performance at a lower price.
  • Time savings: Because they offload all of the server maintenance and ops work onto the cloud providers, serverless architectures free up developers, giving them time to focus on the more important work of building their applications.

When not to use serverless architecture

Serverless architectures aren’t the best choice for every use case, however.

If you require detailed control over the machines your application is running on, either for performance or security reasons, serverless architecture may not be the best choice, since that work is offloaded to the cloud providers.

Serverless architectures aren’t always cheaper, either – there are certainly cases, particularly for larger enterprises, where dedicated machines can end up being the more affordable choice. Vendor lock-in with many serverless services can also be a problem that leads to increased costs.

Additionally, not all serverless platforms and cloud providers are created equal. Issues like slow cold starts can actually make your application’s performance worse, so it’s important to look at the details when it comes to choosing any sort of serverless provider.