FaaS: Run Code, Not Servers
FaaS lets you run code without managing servers, like renting a contractor for one task. It's ideal for event-driven actions like processing uploads or handling webhooks. The footgun is cost: for high, steady traffic, a dedicated server is often cheaper.
Why it exists
Before FaaS, even a small, infrequently run task required a server (physical or virtual) that you had to provision, patch, scale, and pay for 24/7. FaaS was created to eliminate this operational overhead and wasted cost for event-driven workloads, allowing developers to focus purely on business logic.
The mental model
Think of FaaS not as renting a server, but as renting execution time. You provide a piece of code (a function) and tell the cloud provider, "Run this only when X happens." The provider handles finding a machine, running the code in a temporary environment, and then tearing everything down. You only pay for the milliseconds your code is actually running.
How it works
You upload your code as a self-contained function and configure a trigger, which is an event that will cause it to execute. Triggers can be an HTTP request, a new file in a storage bucket, a message in a queue, or a scheduled time. When the trigger fires, the FaaS platform instantly provisions a container, loads your code, executes it with the event data as input, and then shuts the container down. The platform manages all scaling automatically.
When to use it
FaaS is ideal for stateless, short-lived, event-driven tasks. Good examples include: building API backends for single-page applications, processing data streams, running scheduled cron jobs, and creating "glue code" between different cloud services. It excels with unpredictable or "spiky" traffic patterns where resources can scale from zero to thousands and back down.
When not to use it
Avoid FaaS for long-running, stateful applications or tasks with constant, high-throughput workloads. The "cold start" latency (the time to provision a new container for the first time) can be an issue for applications requiring immediate, low-latency responses. For sustained traffic, the pay-per-invocation model can become more expensive than a dedicated server or container running 24/7.
One canonical example
A user uploads a profile picture to your app's cloud storage bucket. The upload event triggers a FaaS function. This function takes the newly uploaded image, generates three different thumbnail sizes (small, medium, large), and saves them back into the storage bucket. The entire process happens automatically without any server to manage, and you only pay for the few hundred milliseconds of compute time the image resizing took.
Interview question
Which application characteristic would make a FaaS solution generally less cost-effective or suitable compared to traditional server-based hosting?
- a.The application processes infrequent, event-driven tasks.
- b.The application is a long-running, stateful service with consistent, high throughput.Correct
- c.The application requires automatic scaling from zero to handle spiky traffic.
- d.The application needs to integrate with other cloud services via "glue code".
Why? this is the answer
The card explicitly states to "Avoid FaaS for long-running, stateful applications or tasks with constant, high-throughput workloads" because the pay-per-invocation model can become more expensive than a dedicated server for sustained traffic. The other options describe scenarios where FaaS is highly suitable due to its event-driven nature and automatic scaling capabilities.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles