Ravindra BagaleCourses & study guides मराठी Track your progress

Serverless Cost Modelling, Quotas and Service Limits Explained

Serverless feels cheap until a loop, a fan-out, or a forgotten log retention burns the card. Model cost at 1x and 10x traffic in USD and INR, check Service Quotas in ap-south-1, and leave concurrency headroom — before launch day.

What you'll learn in this chapter

  • Build a simple monthly cost model
  • Read key Lambda and API quotas
  • Set a budget alarm habit
  • Spot runaway patterns early
  • Link pricing deep chapters

1. Everyday example: Rohan's surprise bill

Rohan in Pune (INR) shipped a webhook Lambda. A partner retried every second for a weekend. Invocations exploded; CloudWatch Logs stored every payload. Monday Cost Explorer told the story — after the bill.

Metrics and logs: CloudWatch. Compute: Lambda. Bills: Cost Explorer / Billing console (enable once).

2. Why model cost and quotas?

Why do we need this?

Pay-per-use rewards good design and punishes chatty design. Quotas are soft walls: hit them and users see 429/throttles even if money remains. Modelling forces honest traffic assumptions.

What is it?

Cost modelling = estimate units (invocations, GB-s, requests, RCU/WCU, log GB) times price. Quotas = account/region service limits. Reserved concurrency = protect critical functions.

3. Vertical diagram

Estimate traffic -> price lines -> quotas -> headroom -> budget alarmNever launch blind on free tier stories
Alarm before finance does
Traffic estimate (1x and 10x) Service pricing lines (Lambda, API, DDB) Account quotas in ap-south-1 Concurrency and burst headroom Budget alarm + Cost Explorer habit Model before launch day
Cost and quotas before traffic.

4. How: quick model sheet

How to do it (step by step)

LineUnit to countWatch-out
Lambda invokeRequests/monthRetries + DLQ redrive double-count
Lambda durationGB-secondsMemory too high burns money
API GatewayHTTP requestsChatty mobile clients
DynamoDBRCU/WCU or on-demandHot partition + scans
LogsIngest + storage GBDebug payloads in prod
X-RayTraced segments100% sampling

5. Commands

Account Lambda settings (concurrency)

aws lambda get-account-settings --region ap-south-1

Meaning: See unreserved concurrent executions remaining.

Service quotas sample (Lambda concurrent)

aws service-quotas list-service-quotas --region ap-south-1 \
  --service-code lambda --query 'Quotas[?contains(QuotaName, `Concurrent`)].{N:QuotaName,V:Value}' --output table

Meaning: Confirm concurrent execution quota before Black Friday.

Cost Explorer style daily spend (CLI needs ce enabled)

aws ce get-cost-and-usage --time-period Start=2026-10-01,End=2026-11-01 \
  --granularity MONTHLY --metrics UnblendedCost \
  --group-by Type=DIMENSION,Key=SERVICE --query 'ResultsByTime[0].Groups[:5]' 

Meaning: Enable Cost Explorer in console once; then CLI works.

Log group retention audit

aws logs describe-log-groups --region ap-south-1 \
  --query 'logGroups[?retentionInDays==`null`].logGroupName' --output text | head

Meaning: null retention = keep forever = surprise bill.

6. Runaway patterns

  • Lambda writing to a bus that triggers the same Lambda.
  • SQS visibility shorter than processing — poison redrive storm.
  • API client with no backoff hammering 5xx.
  • DEBUG logs with full bodies in prod.
  • Provisioned concurrency left on unused aliases.

7. Industries

  • Fintech (Aisha, Lagos, NGN): budget alarms on ledger path; never surprise CFO.
  • Ecommerce (Rohan, Pune, INR): model festival 10x; raise quotas early.
  • Media (Mei, Singapore, SGD): image Lambda GB-s dominate — right-size memory.
  • SaaS (Priya, Bengaluru, INR): per-tenant cost attribution via tags.
  • IoT (Omar, Amman, JOD): device reconnect storms — throttle + DLQ.

8. Lab

9. Lab - model and alarm

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

How to do it (step by step)

  1. Write a 1x and 10x invoke estimate for one API.
  2. Run get-account-settings; note concurrent limit.
  3. Find one log group with null retention; plan a number.
  4. Create or inspect a monthly budget alert in sandbox.

Cleanup (stop billing)

  1. Delete sandbox budgets you do not need.
  2. Do not change prod retention without change ticket.

10. Same pattern across industries

  • Fintech (Aisha, Lagos): payment webhooks → SQS → Lambda; never block the bank callback thread.
  • Ecommerce (Rohan, Pune): checkout API on API Gateway+Lambda; inventory fan-out on SNS.
  • Healthcare (Mei, Singapore): appointment SMS via SNS; PHI stays in DynamoDB with fine-grained IAM.
  • EdTech (Diego, São Paulo): nightly cleanup EventBridge → Lambda on student drafts.
  • Logistics (Fatima, Casablanca): package scan events on EventBridge bus; Step Functions for customs saga.
  • Media (Kenji, Osaka): S3 upload → Lambda thumbnails; fan-out to moderation + CDN invalidate.
  • SaaS multi-tenant (Priya, Bengaluru): Cognito groups + DynamoDB partition per tenant.
  • Gov portal (Omar, Amman): strangler fig — peel one PDF form route per sprint to Lambda.

11. Troubleshooting checklist

  1. Confirm region (ap-south-1 vs us-east-1 for CloudFront/ACM quirks).
  2. Check CloudWatch Logs for the function name and request id.
  3. Verify IAM execution role allows the API you call.
  4. For async: check DLQ depth and SQS age of oldest message.
  5. For APIs: curl -v and compare status, CORS headers, body.
  6. For workflows: open Step Functions execution event history.
  7. Re-read the linked deep chapter before reinventing a service.
  8. If cost spikes: check concurrency, retries, and provisioned capacity.

12. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Assumed free tier foreverModel real traffic; free tier is training wheels.
No budget alarmCreate AWS Budgets + SNS.
Hit concurrent limit on launchRequest quota increase early; reserve critical.
Logs never expireSet retention 7-30d unless compliance says else.
Memory 3008 for hello worldRight-size with Lambda Power Tuning habit.
Ignored retries in costCount client + SQS retries.
On-demand DDB surpriseWatch consumed capacity; consider keys.
X-Ray 100% samplingSample user paths.
Wrong currency talkShow USD and INR for stakeholders.

13. FAQ

Q. Is serverless always cheaper?

At spiky low traffic often yes; steady high may favor containers — model both.

Q. What is reserved concurrency?

Caps a function so others keep headroom; also protects that function's slice.

Q. Where are quotas?

Service Quotas console/CLI per region.

Q. Link CloudWatch cost?

amazon-cloudwatch-metrics-namespaces-alarms-and-sns-email-alerts.

Q. Provisioned concurrency cost?

You pay for ready execution environments — use for latency SLOs carefully.

14. Interview Q&A (Beginner / Mid / Senior + MNC)

Q. Beginner: what bill lines for Lambda?

Invokes + duration GB-s + logs.

Q. Beginner: what is a quota?

Limit on how much you can use in a region/account.

Q. Mid: how to estimate?

Units times price at 1x and 10x.

Q. Mid: runaway loop sign?

Invocation spike + same request ids cycling.

Q. Senior: multi-account cost?

Tags + CUR + allocation; budgets per OU.

Q. MNC: evidence?

Budget history, quota tickets, launch checklist signed.

15. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Model 1x and 10x, set a budget alarm, leave concurrency headroom — then ship.

Ravindra Bagale's Tip (MR)

1x/10x model, budget alarm, concurrency headroom — मग ship.

Tip (HI)

1x/10x model, budget alarm, concurrency headroom — फिर ship।

Try at home

  1. Estimate one API monthly invokes.
  2. Check Lambda account settings.

In short

  1. Start from a real story, then name the AWS services.
  2. Link existing chapters — do not copy their labs.
  3. Design for failure: retries, DLQ, idempotency, rollback.
  4. Measure before you buy provisioned concurrency or multi-region.

16. Architecture decision checklist

  1. Write the user journey in five bullets with no AWS names.
  2. Mark each step sync (user waits) or async.
  3. Name failure mode: retry, DLQ, compensate, or alert-only.
  4. Name the idempotency key for every write.
  5. Pick data store from access patterns (link DynamoDB modeling).
  6. Estimate monthly cost at 1x and 10x traffic (USD and INR).
  7. Confirm account concurrency and service quotas in ap-south-1.
  8. Decide auth: Cognito, IAM, Lambda authorizer, or none.
  9. Name on-call and which CloudWatch alarm pages them.
  10. Link the deep chapter you will not rewrite.
  11. Only then open console or IaC.

17. Copy-paste quick commands (read-only first)

# Region and identity
aws configure get region
aws sts get-caller-identity

# Lambda landscape
aws lambda list-functions --region ap-south-1 --max-items 20 \
  --query 'Functions[].{N:FunctionName,R:Runtime,T:Timeout,M:MemorySize}' --output table
aws lambda get-account-settings --region ap-south-1

# API Gateway (HTTP APIs)
aws apigatewayv2 get-apis --region ap-south-1 --query 'Items[].{N:Name,Id:ApiId,Ep:ProtocolType}' --output table

# Queues and topics
aws sqs list-queues --region ap-south-1
aws sns list-topics --region ap-south-1 --query 'Topics[].TopicArn'

# Event buses and state machines
aws events list-event-buses --region ap-south-1
aws stepfunctions list-state-machines --region ap-south-1 --query 'stateMachines[].name'

# DynamoDB tables (names only)
aws dynamodb list-tables --region ap-south-1

Run these in a sandbox account. Prefer read-only IAM while learning.

18. More industry and stack stories

  • Fintech (Aisha, Lagos, NGN): bank webhooks must return 200 fast — SQS absorbs spikes; ledger Lambda is idempotent on paymentId.
  • Ecommerce (Rohan, Pune, INR): Black Friday — API Gateway throttle + SQS order intake; SNS fans inventory, email, analytics.
  • Healthcare (Mei, Singapore, SGD): appointment reminders via SNS SMS; PHI only in DynamoDB with condition keys.
  • EdTech (Diego, São Paulo, BRL): EventBridge nightly cleanup of draft quizzes; Lambda timeout 30s, not 15 min.
  • Logistics (Fatima, Casablanca, MAD): package scans on custom EventBridge bus; Step Functions customs saga.
  • Media (Kenji, Osaka, JPY): S3 → Lambda thumbnails; never write thumbs to the watched prefix.
  • SaaS (Priya, Bengaluru, INR): Cognito groups + DynamoDB PK tenantId; one Lambda authorizer for all routes.
  • Gov (Omar, Amman, JOD): strangler — peel one PDF form route per sprint from the monolith.
  • Startup (Sofia, Sofia, EUR): start with Function URL for demos; move to HTTP API when partners need JWT.
  • Retail (Luis, Mexico City, MXN): store POS sync via SQS FIFO when order matters; Standard when it does not.
  • Python: handlers thin; put domain logic in plain modules for unit tests without Lambda.
  • Node: prefer async/await; never block the event loop on sync DNS.
  • Java: SnapStart for cold starts; keep dependencies lean.
  • .NET: AspNetCoreServer for low-traffic tenants; watch package size.
  • Go: single static binary; great for SQS workers.
  • PHP: keep Laravel queues on ECS; Lambda for S3/webhooks glue.

19. Glossary (short)

TermMeaning
Cold startFirst invoke pays init; later invokes reuse the env
IdempotencySame request twice → same effect
DLQDead-letter queue for failed messages
ChoreographyServices react to events; no central conductor
OrchestrationCentral workflow (Step Functions) directs steps
Fan-outOne event → many consumers
Fan-inMany branches join before next step
Strangler figPeel routes from monolith gradually
SagaDistributed tx via steps + compensations
Provisioned concurrencyKeep N envs warm; you pay for ready capacity

20. Practice: explain out loud

  1. 60 seconds: everyday story for serverless cost quotas.
  2. 60 seconds: sync vs async with a checkout example.
  3. 60 seconds: when you refuse Lambda.
  4. 60 seconds: DLQ + idempotency in one breath.
  5. Record once; cut fillers; record again.

21. Safe lab hygiene

  • Tag every lab resource with owner and expiry date.
  • Set a monthly AWS Budget alarm in INR or USD before experiments.
  • Prefer read-only commands first; mutate in a sandbox account.
  • Delete queues, APIs, tables you created — DynamoDB and APIGW leave footprints.
  • Never put production secrets in env vars or screenshots.
  • Do not enable provisioned concurrency for a hello-world.

23. Myths to drop

MythReality
Serverless means zero serversServers exist; you do not manage them
Always cheaper than EC2Steady high load can favor EC2/Savings Plans
No Ops neededYou own IAM, data, alarms, cost, incidents
One Lambda per app is fineBounded contexts scale better
Queues are optional decorationQueues are the load leveler and blast-radius wall

24. Error budget thinking for serverless

If your monthly error budget is 0.1% on checkout, a fan-out that retries aggressively can burn the budget with duplicate emails while money stays correct. Separate business correctness SLOs from notification SLOs.

  1. Write two SLOs: money-correct and notify-delivered.
  2. Retries on money path: bounded + idempotent.
  3. Retries on notify path: best-effort + DLQ.
  4. Page humans on money DLQ; ticket on notify DLQ.

25. Regional notes (ap-south-1)

  • Build labs in Mumbai (ap-south-1) unless your org mandates elsewhere.
  • Some services launch first in us-east-1 — check feature availability.
  • Data residency for INR fintech may require in-region only.
  • Latency to end users in India usually favors ap-south-1.

26. Naming conventions that save incidents

# Suggested prefixes
# Lambda:  pay-intake-prod, pay-worker-prod
# SQS:     pay-orders.fifo / pay-orders-dlq
# SNS:     pay-order-events
# EB bus:  pay.domain
# SFN:     pay-refund-saga
# DDB:     pay-orders-prod

Include env (dev/stage/prod) and domain. Future you grepping CloudWatch will thank present you.

27. Pre-mortems (ten minutes)

  1. Imagine tomorrow headline: double charge in AED. What broke?
  2. Imagine DLQ depth 50,000 after a bad deploy. How do you drain?
  3. Imagine Cognito outage. Do APIs fail closed or serve read-only?
  4. Write answers in the runbook before go-live.

28. Currency and locale in examples

Rotate currencies in designs: INR, USD, EUR, AED, NGN, BRL, JPY, SGD. Rotate names: Aisha, Rohan, Mei, Diego, Fatima, Kenji, Priya, Omar, Sofia, Luis. This keeps mental models global — not one-country samples.

29. Worked story: festival 10x (INR)

  1. Rohan models Diwali 10x checkout.
  2. Service Quotas show concurrent too low.
  3. Request increase + reserved concurrency on pay.
  4. Budget alarm at 80 percent — finance calm.

30. Anti-patterns

  • Shipping without a cost owner.
  • Debug logging left on in prod.
  • Ignoring Service Quotas until launch day.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Model 1x and 10x. Free-tier stories fail on festival traffic. Count invokes, GB-s, API requests, DDB, logs — USD and INR. Check Service Quotas and concurrency headroom before launch. Rohan models Diwali 10x then requests a quota bump.
Revision card: Model 1x and 10x · Download PNG · Open card page
Revision card: Stop runaway spend. Loops, fat DEBUG logs, and idle provisioned concurrency burn money. Budget alarms and retention policies are first-class controls. Right-size memory; sample traces; count retries in the model. Aisha pages on ledger spend spike — not on notify DLQ.
Revision card: Stop runaway spend · Download PNG · Open card page
Comparison: Guess free tier vs Model 1x/10x. Guess free tier: Ship and wait for the bill. Model 1x/10x: Units × price at 1x and 10x in USD/INR.
Comparison: Guess free tier vs Model 1x/10x · Download PNG · Open card page
Comparison: Account pool only vs Reserved concurrency. Account pool only: Every function fights the account concurrent limit. Reserved concurrency: Cap critical fn; leave headroom for others.
Comparison: Account pool only vs Reserved concurrency · Download PNG · Open card page
Interview card: Lambda bill lines?. Invocations, duration GB-seconds, and log ingest/storage. Retries and client hammers multiply invokes. MNC: show a 1x vs 10x sheet.
Interview card: Lambda bill lines? · Download PNG · Open card page
Interview card: What is a quota?. Account/region service limit — soft wall under load. Request increases early; reserve concurrency for critical paths. MNC: who owns the quota ticket?
Interview card: What is a quota? · Download PNG · Open card page
Interview card: Reserved concurrency?. Caps one function and protects others' headroom. Use on payment paths before Black Friday. MNC: trade-off vs account pool only?
Interview card: Reserved concurrency? · Download PNG · Open card page
Interview card: Null log retention?. Means keep forever — surprise storage bill. Set 7–30 days unless compliance says otherwise. MNC: evidence of retention policy?
Interview card: Null log retention? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Vidarbha Cotton Mills is a textiles business in Nagpur. Ganesh Wankhede looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Count invokes — 1

Why: Idea.

What to do: Enter 1 if Lambda cost models count invocations.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy GB-seconds matter — 1

Why: Idea.

What to do: Enter 1 if duration GB-seconds drive Lambda cost.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Log retention cost — 1

Why: Idea.

What to do: Enter 1 if forever log retention raises cost risk.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Quotas are limits — 1

Why: Idea.

What to do: Enter 1 if Service Quotas are account/region limits.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Model 10x — 1

Why: Idea.

What to do: Enter 1 if you should model 1x and 10x traffic.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Count retries — 1

Why: Idea.

What to do: Enter 1 if cost models must count retries.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Free tier not forever — 1

Why: Idea.

What to do: Enter 1 if free tier is not a forever prod plan.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Reserved concurrency — 1

Why: Idea.

What to do: Enter 1 if reserved concurrency protects critical functions.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Budget alarm — 1

Why: Idea.

What to do: Enter 1 if AWS Budgets alarms catch spend early.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Self-trigger loop — 1

Why: Idea.

What to do: Enter 1 if a Lambda re-trigger loop can explode cost.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Provisioned costs — 1

Why: Idea.

What to do: Enter 1 if provisioned concurrency bills warm environments.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Throttle on limit — 1

Why: Idea.

What to do: Enter 1 if hitting concurrent limits throttles users.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Cost model keys

Why: Sheet.

What to do: YAML: invokes: 1000000 and gbs: 400000 for a sketch.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Medium Lambda account settings

Why: Concurrency.

What to do: Get Lambda account settings

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Hard USD and INR — 1

Why: Idea.

What to do: Enter 1 if stakeholders should see USD and INR.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Null retention bad — 1

Why: Idea.

What to do: Enter 1 if null log retention means keep forever.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.