Function as a service (FaaS), also known as serverless functions, represents a paradigm shift in cloud computing services, where developers can deploy individual functions to the cloud without managing the underlying cloud infrastructure. FaaS platforms like AWS Lambda, Google Cloud Functions, Microsoft Azure Functions, IBM Cloud Code Engine, MongoDB Atlas App Services Functions, and other cloud computing services handle the deployment, execution, and scaling of these functions.
FaaS simplifies the deployment and management of application code by utilizing a consumption-based pricing model, which charges based on actual resource usage. Such platforms allow developers to focus solely on writing and executing FaaS code using application programming interfaces (APIs) while the underlying infrastructure and network resources are managed by the service provider. This approach is ideal for breaking away from monolithic architecture, enabling the development of scalable, event-driven applications.
The key benefit to developers is FaaS gives teams the ability to run individual functions in response to events without managing servers. It’s ideal for mobile apps, scheduled tasks, and horizontally scalable scenarios. Developers write code in discrete functions, which FaaS platforms execute in response to triggers. This approach simplifies the development process, enabling rapid deployment of applications.
Table of contents
The core principle of function as a service is to decouple the deployment and execution of application code from the underlying infrastructure. This is achieved by hosting functions on public cloud services like AWS Lambda, Google Cloud Functions, MongoDB App Services, and other cloud computing models. These public cloud platforms abstract the hardware and automatically manage the scaling and execution of functions based on incoming requests.
The key advantages of FaaS are:
For organizations, the key advantage of FaaS is its cost efficiency. Since billing is based on actual execution time, FaaS differs from other models because developers are not charged for idle resources. This model is particularly advantageous for applications with intermittent or unpredictable workloads, such as scheduled tasks, data processing pipelines, and real-time data analytics.
FaaS supports a range of major programming languages and runtime environments, providing many organizations with the flexibility to choose the best tools for their tasks. Each FaaS provider has its own set of supported languages and APIs, which ensure developers can use familiar technologies and frameworks, further streamlining the development process.
FaaS can integrate seamlessly with your cloud computing service, enabling the creation of complex, event-driven architectures. Events include HTTP requests, database changes, and message queue triggers that can automatically invoke functions, facilitating real-time processing and responsiveness.
There is a range of FaaS providers and each supports a unique set of languages for software developers writing functions with different characteristics and limitations. Choosing a cloud service that aligns with your development environment and ecosystem is essential.
Mongo DB Atlas App Services Functions are ideal for developers who want tight integration with MongoDB without relying heavily on external cloud services. This platform supports features like git repository integration for automated deployments, direct function editing in the browser, and robust security mechanisms. By leveraging MongoDB Atlas App Services Functions, developers can build highly responsive, data-driven web apps with minimal configuration and maintenance overhead.
MongoDB's Atlas Functions allow you to write JavaScript functions, with automatic integration with your MongoDB database cluster. These functions are automatically integrated with MongoDB Atlas databases, offering a seamless development experience. These functions can be triggered in various ways, including:
Schedule-based: As cron jobs to perform tasks like dataset maintenance or calculating computed fields
Change-based: Triggered by any changes in the database; useful for actions like adding vectors to documents for datasets using Vector Search
Amazon was the first public cloud provider to release a FaaS product. AWS Lambda natively supports functions written in Java, Go, PowerShell, Node.js, C#, Python, and Ruby. They also provide an API that allows you to write your functions in any programming language you prefer.
Lambda's integration with MongoDB Atlas is seamless, particularly since MongoDB Atlas clusters, including serverless instances, can be hosted on AWS, and a connection between both can be established through VPC peering.
This tight integration allows developers to build scalable and high-performance applications with minimal operational overhead. For more details, read about AWS Lambda functions with MongoDB.
Google's Cloud Function offers robust support for functions written in Node.js, Python, Go, Java, C#, Ruby, and PHP. As a part of the Google Cloud ecosystem, it provides deep integration with other Google services like BigQuery, Cloud Pub/Sub, and Firebase, making it a versatile choice for developers.
MongoDB clusters can be hosted on Google Cloud, facilitating smooth integration with Google Cloud Functions.
By using Google Cloud Functions with MongoDB Atlas, developers can create event-driven architectures where functions are triggered by changes in the database or other Google services, ensuring efficient and responsive application performance.
Microsoft's Azure Functions allows you to write functions in C#, JavaScript, F#, Java, PowerShell, Python, and TypeScript. Azure Functions are designed to integrate seamlessly with other Azure services such as Azure Cosmos DB, Azure Storage, and Azure Event Grid.
MongoDB Atlas supports deployment on Azure, making Azure Functions a suitable option for applications that leverage Microsoft's cloud ecosystem.
For example, developers can use Azure Functions to process real-time data streams, handle scheduled tasks, or integrate with other Azure services, while using MongoDB Atlas as the primary database.
FaaS platforms package function code into containers. The host platform then manages the routing of events to the function containers and scales them up or down as demand requires. This setup abstracts away the need for developers to manage infrastructure, allowing them to focus solely on writing application logic.
FaaS is a specialized subset of serverless computing. It refers to platforms that abstract away the hardware, enabling developers to focus on code. These platforms usually charge on a per-usage basis, and ideally they scale to zero, meaning minimum cost for applications when they are not in active use. FaaS specifically involves running discrete functions in response to events, providing an efficient and scalable solution for executing code without managing servers.
The main advantages of FaaS are:
The primary disadvantages of FaaS include the following:
FaaS architectures are event-based. Your functions are triggered by events such as HTTPS requests, messages from a message queue, scheduled triggers, or calls from another hosted function.
In a FaaS environment, functions are ideally stateless, which allows independent scaling by the host platform. While each function may be hosted in a separate VM or server, leading to limited persistent or shared state, this design encourages functional programming best practices. Stateless functions promote a functional programming approach, which enhances modularity, reusability, and maintainability for modern applications.
Functions are charged for the amount of time they execute. For this reason, it can be a good idea to optimize to keep the startup time and running time as low as possible. Each platform will have a time limitation after which functions will be forcibly shut down, so for this reason, it's important to ensure that functions at least execute in a reasonable amount of time.
Functions can scale more or less linearly, providing you can store your functions' data in a suitably scalable database (like MongoDB!).
In applications where the application builds up significant state in memory, a FaaS solution may not be suitable.
Because MongoDB Atlas can deploy and manage clusters on all the three major cloud platforms (or even across two or more platforms!), choosing a particular cloud provider's function offering comes down more to the other services offered by that cloud platform. If you're integrating between your cloud provider's function offering and MongoDB, you have two choices. The first is to use the MongoDB driver for your language (such as PyMongo for Python functions).
When using the native MongoDB driver, ensure that the driver is cached between function calls. There's a cost to initializing the MongoDB driver, and so if you can share instances between different function calls, that will reduce your functions' run time. Take a look at the Developer Center for more best practices around MongoDB and AWS Lambda.
Another choice would be the MongoDB Atlas App Services platform, which provides functions as a service. App Services supports functions written in JavaScript and provides git repository integration for automated deployment, as well as the ability to write functions directly in the browser.
FaaS is good for applications without shared or persistent state that must be stored in RAM. Following functional programming best practices, this makes it particularly suitable for applications where shared state is stored in a database, meaning that the functions can spin up and execute in the minimum amount of time, storing all necessary data in the underlying database. Obviously, this means that your database needs to be able to scale alongside the execution of your FaaS functions. Fundamentally, the key features of functions as a service are: Ease of deployment. Pay-as-you-go cost model Automatic scaling of functions. If these fit your requirements, then FaaS may be a good choice for you.
Generally, yes. FaaS is a platform that is usually provided by your cloud provider. But there's nothing to stop you from hosting your own instance of faasd (a lightweight FaaS server) and hosting your own functions on something as simple as a Raspberry Pi! The primary thing that differentiates FaaS from other architectures is the ability to deploy one or more functions to a system that will handle running them independently.
PaaS (or platform as a service) is commonly used to describe cloud platforms that abstract away the infrastructure that they run on. A good example is Vercel, which allows developers to build Next.js applications and deploy them to Vercel's infrastructure without worrying about how that underlying infrastructure works.
In this way, FaaS can be considered a subset of PaaS, where the underlying unit of code is a function, which is a relatively simple unit consisting of inputs, outputs, and persistent services (like databases) that are available for various tasks.
CaaS is short for containers as a service. The primary difference between CaaS and FaaS is that although both are deployed within containers (or lightweight VMs, in the case of AWS Lambda), in the case of CaaS, you have full control over the contents of the container. With a CaaS platform, you would author an entire service (usually following microservice idioms) and then package that up as a container. The host CaaS platform takes care of deploying, maintaining, and scaling these containers as necessary.
With a FaaS platform, the developer doesn't have control over the contents of the container. The developer only has control over the function's code and a list of dependencies required by that code. The rest of the container's contents is managed by the FaaS platform, and provides the necessary processes and supporting code to run and monitor the deployed function.