
What is Serverless Architecture and When Should It Be Used?
June 25, 2025Serverless architecture is a way of building applications where you write code and configure managed services, while the cloud provider runs, scales and patches the infrastructure underneath. Servers still exist; you just never provision, size or maintain them. For many products this removes real operational work; for others it adds cost a plain container would avoid.
What serverless actually means
The term covers two things. Functions as a service (FaaS), such as AWS Lambda, Azure Functions or Google Cloud Functions, run small units of code in response to an event and stop when the work is done. Managed backend services, such as databases, queues, storage, authentication and API gateways, are used through an API and billed by usage, with no instances to run. Serverless containers like Google Cloud Run sit in between: you ship an image and the platform handles scaling.
Four properties define the model:
- Event-driven. Code runs because something happened: an HTTP request, a file upload, a queue message, a database change or a timer.
- Automatic scaling. Capacity follows demand, with no autoscaling rules to tune.
- Scale to zero. When nothing happens, nothing runs, and you typically pay nothing for compute.
- Pay per use. You pay for invocations, execution time and requests, not reserved capacity.
Serverless is one way to build cloud-native applications, not a synonym for them, and many systems combine it with containers.
How a request flows
A mobile app saves a user's profile. It sends an HTTPS request with an access token. An API gateway checks the token, applies rate limits and routes the call to a function. If no warm instance is available, the platform starts one; that delay is the cold start. The function writes to a managed database and responds. The database change can trigger another function, for example to update a search index, without slowing the user's request.
Typical building blocks
- Functions for business logic.
- API gateway for routing, token checks and throttling.
- Managed databases, such as DynamoDB or Firestore, or relational databases with serverless scaling.
- Queues and event buses to decouple services and absorb spikes.
- Object storage for files and media, often emitting events on upload.
- Managed authentication, such as Amazon Cognito or Firebase Authentication.
- Workflow orchestration, such as AWS Step Functions, for processes that outlive a single function call.
When serverless is a good fit
- Spiky or unpredictable traffic: campaigns, ticket sales, seasonal products, B2B tools used only in office hours. Idle time between peaks costs nothing.
- Event processing: resizing images, parsing documents, reacting to payments or IoT messages, where each item is independent.
- Scheduled jobs: nightly reports, syncs and cleanups that would otherwise keep a server alive for minutes of work a day.
- MVPs and prototypes: less infrastructure means the first weeks go into the product, and costs stay near zero until users arrive.
- Integrations and webhooks: receiving callbacks from payment providers or CRMs, transforming them and passing them on.
- Mobile backends: sign-in, user data, uploads and push notifications map well to managed services and a few functions.
When it is the wrong tool
- Long-running work. Functions have execution time limits. Video transcoding and long-lived connections belong in containers or batch services.
- Steady high load. A service busy around the clock usually costs more per invocation than on reserved containers or VMs. Pay per use rewards idle time; without it, the advantage disappears.
- Latency-sensitive paths. Cold starts delay the first request on a new instance. Keeping instances warm is possible but billed, which partly undoes scale to zero.
- Lock-in concerns. Triggers, permissions, event formats and managed databases are provider-specific, so moving later means rewriting glue code and sometimes the data layer. The trade-off resembles owning your code versus building on a platform.
- Complex in-memory state. Multiplayer sessions or real-time collaboration engines fight a stateless, short-lived model.
How to think about cost
At low and uneven volume, pay per invocation usually beats always-on capacity. As volume grows and steadies, the curves cross, and where depends on traffic shape, memory settings and execution time. Model it with the provider's pricing calculator at expected volume and at ten times that before committing.
The surprises are rarely the invocations themselves:
- Data transfer out of the cloud and between regions or zones.
- Logging, where verbose logs at high volume can cost more than compute.
- API gateway fees, charged per request on top of function costs.
- Private networking, such as NAT gateways for functions that call external APIs from a private network.
- Retries and runaway loops that multiply invocations.
- Warm capacity, billed whether used or not.
Set budgets and cost alerts on day one, and tag resources by feature.
Operational trade-offs
Serverless moves operational work rather than removing it. Observability gets harder when one user action crosses a gateway, several functions and a queue; you need structured logs, correlation IDs and distributed tracing, for example with OpenTelemetry. Local testing is limited: emulators such as AWS SAM CLI or the Firebase Local Emulator Suite cover the basics, but permissions and event formats only behave fully in the cloud, so plan short-lived test environments per branch. Platform limits on execution time, payload size and concurrency differ by provider and plan, so check current documentation, such as the AWS Lambda pages.
Two habits prevent many incidents. Make handlers idempotent, because event sources can deliver the same message twice. And protect relational databases from connection storms when many function instances start at once, using a connection proxy. With this many moving parts, infrastructure as code is mandatory; it is also why we set up CI/CD and automated testing on every project from the start.
Decision checklist
- Is traffic spiky, seasonal or low for long periods?
- Does each unit of work finish well within the platform's time limit?
- Can the logic be stateless, with state in a database or storage?
- Can the critical path tolerate occasional cold starts, or is there budget for warm capacity?
- Have you estimated cost at ten times expected volume, including gateway, data transfer and logs?
- Is the lock-in acceptable, with core logic kept separate from provider-specific code?
- Do the managed services meet your compliance and data residency needs?
Mostly yes points to serverless; mostly no points to containers. A mix is often right: a container-based core API with functions for events, jobs and integrations. If the broader cloud decision is still open, see the advantages and risks of moving to cloud computing.
Example: a serverless mobile app backend
This is an illustrative setup, not a template. Imagine an app where users sign up, keep a profile, upload photos and get notifications.
- Sign-in goes through a managed authentication service that issues tokens.
- API calls pass an API gateway that validates tokens and routes to a few functions grouped by domain.
- Data lives in a managed NoSQL database designed around the app's main access patterns.
- Photos upload directly to object storage via short-lived pre-signed URLs; the upload event triggers a thumbnail function.
- Notifications go through a queue to a worker function that calls Firebase Cloud Messaging or Apple Push Notification service.
- Scheduled functions run nightly cleanup and weekly digests.
- Monitoring alerts on error rate, latency and spend.
Watch cold starts on sign-in and home screen calls, and move any endpoint that becomes constantly busy to a container; that is a normal step, not a failure. For the app side, see the key steps for developing an iOS app.
Where to start
Start with one well-suited workload, such as webhooks or a scheduled job, then measure latency and spend for a few weeks before expanding. 4K-Soft has 10+ years of mobile and web development and 100+ released projects, covering the full cycle from idea to support and scaling. If you want a second opinion on serverless for your product, contact our team.