Serverless and container tradeoffs
What you need to know
Serverless functions and long-running containers are deployment models with different process lifetimes and scaling boundaries. Select the model by the workload rather than by a label.
By the end, you can: choose based on workload; identify limits and data locality.
Synthetic database connection budget
{ "maxInstances": 8, "poolPerInstance": 5, "databaseLimit": 50, "reserve": 10, "maximumAppConnections": 40}Expected behavior: 8 × 5 = 40, leaving the intended reserve under the assumed limit. Actual drivers, background processes and concurrent releases can add connections.
How it works
A function platform may start and reuse execution environments on demand, with limits on duration, memory, payload and concurrent requests. A container platform may also scale to zero or impose request deadlines. Verify each product rather than assuming a permanent process or unlimited function execution. Do not use process memory as durable order state. A local cache may disappear, and a background task may stop after the request lifecycle. Store durable state externally and design idempotent jobs with explicit queue ownership. Locate app, cache and database with latency, residency and resilience requirements in mind. Database connections can multiply as concurrency or replica count rises; size a bounded pool and verify total deployment capacity. For example, four old replicas and six new replicas with five connections each can demand 50 connections during rollout, before worker and administrative reserves. This is a conservative planning bound, not a provider measurement. An application with long streams and native packages needs verified streaming, runtime dependencies and timeout support. A small public static site may need neither a container nor a function.
A workload comparison record
{ "workload": "live report", "requiredStreamSeconds": 90, "candidateRequestLimitSeconds": 60, "limitSource": "hypothetical", "decision": "reject this configuration"}Expected behavior: The stated hypothetical limit cannot support the required duration. It does not describe a real vendor.
Common mistake
Calling a service serverless does not make state durable, scaling free or request duration unlimited. Likewise a container can be stopped or rescheduled.
Practice and verification
Compare a static knowledge base, a bursty short API and a sustained report stream. Identify storage, region, concurrency and deadline requirements; calculate worst-case connection demand during overlapping releases.
Scope: Proposed Next.js 16.x / React 19, App Router with Cache Components disabled unless noted. Framework and browser examples are staged, not executed. Hypothetical costs are not actual provider rates.