How to Build Serverless Applications with SST and MongoDB Atlas
Rate this article
is now becoming the standard for how applications are developed in the cloud. Serverless at its core lets developers create small packages of code that are executed by a cloud provider to respond to events. These events can range from HTTP requests to cron jobs, or even file upload notifications. These packages of code are called functions or Lambda functions, named after , the AWS service that powers them. This model allows serverless services to scale with ease and be incredibly cost effective, as you only pay for the exact number of milliseconds it takes to execute them.
However, working with Lambda functions locally can be tricky. You’ll need to either emulate the events locally or redeploy them to the cloud every time you make a change. On the other hand, due to the event-based execution of these functions, you’ll need to use services that support a similar model as well. For instance, a traditional database expects you to hold on to a connection and reuse it to make queries. This doesn’t work well in the serverless model, since Lambda functions are effectively stateless. Every invocation of a Lambda function creates a new environment. The state from all previous invocations is lost unless committed to persistent storage.
Over the years, there has been a steady stream of improvements from the community to address these challenges. The developer experience is now at a point where it’s incredibly easy to build full-stack applications with serverless. In this post, we’ll look at the new way for building serverless apps. This includes using:
“With MongoDB Atlas and SST, it’s now easier than ever to build full-stack serverless applications.” — Andrew Davidson, Vice President, Product Management, MongoDB
Let’s look at how using these tools together can make it easy to build serverless applications.
Lambda functions are packages of code that are executed in response to cloud events. This makes it a little tricky to work with them locally, since you want them to respond to events that happen in the cloud. You can work around this by emulating these events locally or by redeploying your functions to test them. Both these approaches don’t work well in practice.
is a framework for building serverless applications that allows developers to work on their Lambda functions locally. It features something called that proxies the requests from the cloud to your local machine, executes them locally, and sends the results back. This allows you to work on your functions locally without having to redeploy them or emulate the events.
Live Lambda development thus allows you to work on your serverless applications, just as you would with a traditional server-based application.
Traditional databases operate under the assumption that there is a consistent connection between the application and the database. It also assumes that you’ll be responsible for scaling the database capacity, just as you would with your server-based application.
However, in a serverless context, you are simply writing the code and the cloud provider is responsible for scaling and operating the application. You expect your database to behave similarly as well. You also expect it to handle new connections automatically.
You can then make queries to your database, just as you normally would, and everything else is taken care of by Atlas. Serverless instances automatically scale up or down depending on your usage, so you never have to worry about provisioning more than you need and you only pay for what you use.
In this post, we saw a quick overview of the current serverless landscape, and how serverless computing abstracts and automates away many of the lower level infrastructure decisions. So, you can focus on building features that matter to your business!
"MongoDB Atlas’ serverless instances and SST allow developers to leverage MongoDB’s unparalleled developer experience to build full-stack serverless apps." — Jay V, CEO, SST