Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Cloud-native application design

Cloud-native application design explains principles, patterns and trade-offs for building scalable, resilient applications in the cloud using microservices, containers, serverless and managed services.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Cloud-native design is used by engineers to build applications that scale, recover from failures, and change quickly while running on cloud platforms such as AWS. Employers expect you to choose the right architecture (microservices, serverless, containers), trade off consistency vs availability, and map patterns to AWS services referenced elsewhere in the course (for example, AWS Lambda, Amazon API Gateway, CloudFormation, and Terraform).

Key ideas

Start by defining terms before using them.

  • Cloud-native application: an application designed to run on cloud infrastructure using principles such as microservices, containers, automation, and declarative APIs. Assumes dynamic infrastructure and on-demand provisioning.
  • Microservice: a small, independently deployable service that implements a single business capability and communicates over a network. Assumes services are independently deployable and owned by small teams.
  • Container: a lightweight runtime packaging an application and its dependencies so it runs the same in any environment. Example runtimes: Docker. Containers assume an operating-system kernel is shared.
  • Serverless: a hosting model where the cloud provider runs servers and dynamically manages resource allocation; the developer writes code (functions) and pays per invocation. Example: AWS Lambda.
  • Stateless: a service that does not keep client session state between requests. State is stored in external storage (databases, caches, or tokens). Stateless services are easier to scale horizontally.
  • Stateful: a service that stores session or application state locally; harder to scale and requires careful replication.
  • Idempotency: an operation is idempotent if repeating it has the same effect as doing it once. Important for retries.
  • Circuit breaker pattern: a design pattern that stops calling a failing dependency after a threshold of failures to prevent cascading failure. Assume thresholds, timeouts and a half-open recovery mode.
  • Bulkhead pattern: isolate failures by partitioning resources (for example, separate thread pools) so one failure does not take down other functions.
  • Saga pattern: coordinate a long-lived transaction across microservices using a sequence of local transactions with compensating actions instead of two-phase commit.
  • Event-driven architecture: components communicate by sending events to message systems (queues or topics). This decouples services and supports asynchronous work.
  • Observability: collection of logs, metrics and traces to understand runtime behavior. Observability assumes instrumentation is present in code and platform.

Important theorems and statements used in design reasoning:

  • CAP theorem (exact statement): In any distributed data system, it is impossible to simultaneously guarantee all three: Consistency (every read receives the most recent write or an error), Availability (every request receives a non-error response), and Partition tolerance (the system continues to operate despite arbitrary network partitioning). Assumption: network partitions can occur. Derivation used in exams: show that when a partition splits nodes, to remain available both sides must accept writes but then they may diverge (violating consistency). To remain consistent, one side must refuse writes (violating availability).

  • Twelve-Factor App (definition): A set of twelve design rules for cloud-native apps: Codebase, Dependencies, Config, Backing services, Build/Release/Run, Processes, Port binding, Concurrency, Disposability, Dev/prod parity, Logs, Admin processes. Exams often ask to list and map to cloud services; each factor assumes application lifecycle managed with CI/CD.

Diagrams to draw (describe exactly what to draw and label):

  1. Microservices deployment diagram: Draw 6 boxes: User -> API Gateway -> Load Balancer -> Container Cluster (draw 3 small service boxes inside cluster: Service A, Service B, Service C). From Service A draw arrows to: RDS (labelled transactional DB), DynamoDB (labelled key-value store), S3 (object storage), and an SNS or SQS icon (message queue). Label network boundaries: Application Load Balancer (ALB) in public subnets; containers and databases in private subnets. Note: Amazon API Gateway is AWS-managed and not placed in your VPC subnets—use a VPC Link to reach a private ALB/NLB, or integrate with a public ALB. Add labels: "Auto Scaling", "Health checks", "Service discovery".
  2. Event-driven flow: Draw Producer -> Event Bus / Topic -> Consumer(s). Label: "Asynchronous, eventual consistency, retries".

Mapping to AWS (brief pointers, do not re-teach): For API fronting use Amazon API Gateway or Application Load Balancer; for compute use AWS Lambda (serverless) or Amazon ECS/EKS (containers); for data use Amazon RDS (relational), Amazon DynamoDB (NoSQL), Amazon S3 (object); for messaging use Amazon SQS and Amazon SNS; for orchestration and infra-as-code use CloudFormation or Terraform; for identity use Amazon Cognito; for secrets and configuration use AWS Secrets Manager or AWS Systems Manager Parameter Store.

Formulas

For system design we use simple queuing and availability formulas. Units: time in seconds, availability is dimensionless (probability 0..1).

L = λ · W — Little's law. L = average number of requests in the system, λ = arrival rate (requests per second), W = average time in system (seconds). Applies to stable, stationary queueing systems.

Availability = MTBF / (MTBF + MTTR) — Availability as mean-time metric. MTBF = mean time between failures (seconds), MTTR = mean time to repair (seconds). Valid when failures and repairs are approximately exponential and system cycles between up and down.

A_system = 1 - (1 - A_component)^n — Availability of n identical redundant components in parallel. A_component = availability of a single component (0..1). Assumes independent failures.

Backoff for retries (example exponential backoff): delay = base * 2^k where base = initial delay (seconds) and k = retry attempt number (integer). Use jitter to avoid thundering herd.

Idempotency principle (not a numeric formula): To be safe under retries, design API operations so repeated requests do not produce duplicate side effects — e.g., use idempotency keys.

Worked examples

Example 1 — Availability calculation (numerical). Question: You have a microservice deployed as 3 identical instances behind a load balancer. Each instance has availability 0.98. Compute the system availability assuming independent failures.

Steps:

  1. Formula: A_system = 1 - (1 - A_component)^n.
  2. Insert numbers: A_component = 0.98, n = 3.
  3. Compute: 1 - (1 - 0.98)^3 = 1 - (0.02)^3 = 1 - 0.000008 = 0.999992.
  4. Convert to percentage: 0.999992 × 100% = 99.9992%.

Final answer: System availability = 0.999992 (≈ 99.9992%).

Example 2 — Model answer: Design a cloud-native checkout service (long-answer style). Question: Outline a cloud-native design for an e-commerce checkout service meeting goals: resilient, scalable, and cost-efficient. Include where you store state, how to handle payments and retries, and what AWS services you map to.

Model answer (step-by-step):

  1. API layer: Use Amazon API Gateway to accept client requests; validate tokens. API Gateway sits in front of compute and provides authentication, throttling and caching.
  2. Compute: Use AWS Lambda for payment orchestration to reduce cost for spiky traffic; use Amazon ECS/EKS with containers for long-running or CPU-bound tasks. Keep services stateless; move session state out of compute.
  3. State: Store orders in Amazon RDS (ACID transactional store). Use DynamoDB for shopping cart caches or fast lookups. Use Amazon S3 for receipts and invoices.
  4. Asynchrony: Use SQS for decoupling the payment processor from order ingestion; SNS for fan-out notifications. This supports retries and improves availability.
  5. Reliability: Implement idempotent payment operations using unique idempotency keys stored in DynamoDB. Use exponential backoff with jitter on retries.
  6. Fault isolation: Use bulkheads (separate queues and thread pools) and circuit breakers around external payment provider calls.
  7. Observability: Emit structured logs to CloudWatch Logs, metrics to CloudWatch Metrics, and traces to AWS X-Ray (instrumented via OpenTelemetry or the AWS X-Ray SDK). Set alarms for high error rates and latency.
  8. Deployment: Use CI/CD (CodePipeline or Jenkins) and infra-as-code (CloudFormation or Terraform) to automate canary or blue/green deploys.

A full-marks answer lists these choices and explains trade-offs (cost vs latency, consistency vs availability for payments), and describes how idempotency and queues ensure safe retries.

Common mistakes

  • Not including assumptions in availability calculations (independence of failures, identical components).
  • Forgetting idempotency when describing retry strategies.
  • Drawing diagrams without labelling public/private subnets, or failing to show health checks and autoscaling triggers.

For your exam

Kinds of questions you will see:

  • Definitions: define cloud-native, microservice, container, serverless, idempotency, CAP theorem.
  • Short notes: list and map Twelve-Factor App elements to AWS services; explain circuit breaker or bulkhead patterns.
  • Derivations and proofs: explain CAP theorem with a partition example; derive system availability formula for n parallel replicas.
  • Numericals: compute availability with given component availabilities; apply Little's law to compute required capacity for a target latency.
  • Design/program questions: draw a deployment diagram for a microservice architecture; write a checklist for making an API idempotent.

What a full-marks answer includes:

  • Clear definitions (bold terms if asked), stated assumptions, labeled diagrams (components, network zones, data stores), mapping to AWS services (mention names), and explicit trade-offs (consistency vs availability, cost vs latency). For numerical questions, show formula, substituted numbers, units and final boxed answer.

Quick check

  1. What is a microservice?
  2. State Little's law.
  3. Why use idempotency keys with retries?

Answers: Microservice = a small, independently deployable service implementing a single business capability.; L = λ · W where L = avg items in system, λ = arrival rate (s⁻¹), W = avg time in system (s).; To ensure repeated requests or retries do not produce duplicate side-effects, making operations safe under retries.

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?