Knowledge / Computer Applications / Serverless and cloud-native applications

Serverless and cloud-native applications

Computer Applications (MCA) · Mobile, cloud and data · free study notes for exams, placements and interviews

In short

Serverless computing lets a developer deploy individual functions or managed services without provisioning, scaling or patching servers; the cloud provider allocates compute per request and bills only for actual execution. Cloud-native is the broader design style — applications built as loosely coupled, containerised, independently deployable microservices that assume failure, scale horizontally and are managed through automation. Together they are the standard architecture for Indian SaaS and fintech products (Razorpay, Zerodha, Swiggy, Meesho, CRED) and for government platforms built on MeghRaj and the NIC cloud. MCA syllabi examine serverless under cloud computing and advanced web/mobile backends, and GATE DA/CS touches it through distributed systems and virtualisation. Placement rounds ask it as design questions: "how would you build an image-thumbnail service without a server?"

Explained

From physical servers to serverless: the service models

How a FaaS platform executes a function

  1. Deploy: code + dependencies are packaged (zip or container image) with a handler name, memory size, timeout and IAM role.
  2. Trigger: an event source fires — HTTP call through API Gateway, object upload to S3/Blob Storage, message on SQS/Kafka/Pub-Sub, DB stream (DynamoDB Streams), cron (EventBridge/Cloud Scheduler), IoT or mobile SDK call.
  3. Cold start: no warm sandbox exists, so the platform allocates a microVM (AWS uses Firecracker), downloads the package, starts the runtime and runs any initialisation code outside the handler.
  4. Warm invoke: the sandbox is reused for subsequent events — initialisation is skipped, so latency drops to the handler's own execution time.
  5. Concurrency: each concurrent event gets its own sandbox; one sandbox handles exactly one request at a time (no in-process threading model like a web server).
  6. Freeze/thaw: after a response the container is frozen, kept for a few minutes, then reclaimed. Anything in local /tmp or in memory may or may not survive — never rely on it.
  7. Billing: rounded execution time (AWS bills in 1 ms units) × memory allocated, plus a per-request charge. CPU and network scale with the memory setting.

Cold start mitigation: keep packages small, move heavy imports and DB clients to module scope (reused when warm), choose a fast runtime (Go, Node, Python start far quicker than a JVM without AOT), use provisioned concurrency/minimum instances, or SnapStart for Java. Keeping connections to a traditional RDBMS is the classic problem — hundreds of sandboxes exhaust the connection pool, so a proxy (RDS Proxy) or an HTTP-native data store is used.

Serverless design patterns and constraints

Cloud-native: the twelve-factor app and CNCF stack

The twelve factors (Heroku, 2011) are the standard exam list: 1 Codebase in version control, 2 Declared dependencies, 3 Config in the environment, 4 Backing services as attached resources, 5 Separate build/release/run stages, 6 Stateless processes, 7 Port binding, 8 Concurrency by process model, 9 Disposability (fast start, graceful shutdown), 10 Dev/prod parity, 11 Logs as event streams, 12 Admin tasks as one-off processes.

Comparison, cost and security

AspectFaaS (serverless)Containers on KubernetesVM / IaaS
Unit deployedFunctionContainer imageMachine image
ScalingAutomatic, per request, to zeroHPA on CPU/metrics, min ≥ 1 usuallyManual or ASG, minutes
Idle costNilPay for running podsPay for running VM
Startupms to a few seconds (cold start)SecondsMinutes
StateExternal onlyPossible with volumesFull control
Ops burdenLowestHigh (cluster, upgrades)Highest
Lock-inHighLow (portable images)Low
Best forSpiky, event-driven, glue codeSteady load, complex appsLegacy, licensed, special hardware

Key points

Formulas and examples

Lambda-style compute cost = N × M × T × R_gbs + N × R_req
N = invocations; M = memory in GB; T = billed duration in seconds; R_gbs = rate per GB-second; R_req = rate per request. Unit of M × T is GB-second (GB-s).
Billed duration T = execution time rounded up to the billing granularity (1 ms on AWS Lambda).
Required concurrency C = arrival rate λ (requests/s) × average duration d (s) [Little's law]
Effective average latency = p_cold × (t_cold + t_exec) + (1 − p_cold) × t_exec
Monthly VM/container cost = hourly rate × 730 h (average month)
Break-even invocations N* : N × (M × T × R_gbs + R_req) = fixed monthly cost of the always-on option

1. Cost of a thumbnail service (GB-second arithmetic). A function with 512 MB memory runs 400 ms, called 2,000,000 times a month. Take rates of $0.0000166667 per GB-s and $0.20 per million requests (public AWS Lambda list rates; always re-check the current region price).

2. Does more memory cost more? (the counter-intuitive result.) Same function at 1,024 MB finishes in 180 ms because CPU scales with memory.

3. Serverless vs a reserved instance — break-even. An API handler uses 256 MB and 100 ms. An always-on t3.small-class VM costs about $0.0208/h.

4. Concurrency and throttling (Little's law). A results portal gets 5,000 requests/s during a result announcement; each function call takes 250 ms.

5. Cold-start impact on average latency. 10,000 invocations, 300 of them cold. Cold start adds 900 ms; warm execution is 120 ms.

# AWS Lambda handler: S3 upload -> thumbnail -> S3, idempotent
import os, boto3
from PIL import Image          # module scope: reused on warm invokes
s3 = boto3.client("s3")        # client created once per sandbox
DEST = os.environ["DEST_BUCKET"]   # config from environment (factor 3)

def handler(event, context):
    for rec in event["Records"]:                 # at-least-once: may repeat
        src, key = rec["s3"]["bucket"]["name"], rec["s3"]["object"]["key"]
        out = f"thumbs/{key}"
        try:
            s3.head_object(Bucket=DEST, Key=out)  # already done -> skip
            continue
        except s3.exceptions.ClientError:
            pass
        body = s3.get_object(Bucket=src, Key=key)["Body"]
        img = Image.open(body); img.thumbnail((200, 200))
        tmp = f"/tmp/{os.path.basename(key)}"     # /tmp is ephemeral
        img.save(tmp, "JPEG")
        s3.upload_file(tmp, DEST, out)
    return {"statusCode": 200}
NeedServerless choiceWhy
Spiky HTTP APIAPI Gateway + FaaSScales to zero, no idle cost
2-hour video transcodeFargate / BatchExceeds the 15-minute function timeout
Multi-step approval workflowStep FunctionsDurable state, retries, visual audit trail
Mobile login and profile storeBaaS (Firebase/Cognito)Auth, rules and offline sync built in
Steady 500 req/s backendContainers on EKS/Cloud Run min-instancesPast the cost break-even

Where it is used

Interview questions

Common mistakes

Related topics

Cloud computing basics · Containers: Docker and Kubernetes · DevOps and CI/CD basics · Information security fundamentals · Cross-platform apps: Flutter and React Native · Machine learning workflow

Open in the Knowledge reader →Find jobs →