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
4. How: quick model sheet
How to do it (step by step)
| Line | Unit to count | Watch-out |
|---|---|---|
| Lambda invoke | Requests/month | Retries + DLQ redrive double-count |
| Lambda duration | GB-seconds | Memory too high burns money |
| API Gateway | HTTP requests | Chatty mobile clients |
| DynamoDB | RCU/WCU or on-demand | Hot partition + scans |
| Logs | Ingest + storage GB | Debug payloads in prod |
| X-Ray | Traced segments | 100% 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)
- Write a 1x and 10x invoke estimate for one API.
- Run get-account-settings; note concurrent limit.
- Find one log group with null retention; plan a number.
- Create or inspect a monthly budget alert in sandbox.
Cleanup (stop billing)
- Delete sandbox budgets you do not need.
- 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
- Confirm region (ap-south-1 vs us-east-1 for CloudFront/ACM quirks).
- Check CloudWatch Logs for the function name and request id.
- Verify IAM execution role allows the API you call.
- For async: check DLQ depth and SQS age of oldest message.
- For APIs: curl -v and compare status, CORS headers, body.
- For workflows: open Step Functions execution event history.
- Re-read the linked deep chapter before reinventing a service.
- 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 / symptom | Fix |
|---|---|
| Assumed free tier forever | Model real traffic; free tier is training wheels. |
| No budget alarm | Create AWS Budgets + SNS. |
| Hit concurrent limit on launch | Request quota increase early; reserve critical. |
| Logs never expire | Set retention 7-30d unless compliance says else. |
| Memory 3008 for hello world | Right-size with Lambda Power Tuning habit. |
| Ignored retries in cost | Count client + SQS retries. |
| On-demand DDB surprise | Watch consumed capacity; consider keys. |
| X-Ray 100% sampling | Sample user paths. |
| Wrong currency talk | Show 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
- Estimate one API monthly invokes.
- Check Lambda account settings.
In short
- Start from a real story, then name the AWS services.
- Link existing chapters — do not copy their labs.
- Design for failure: retries, DLQ, idempotency, rollback.
- Measure before you buy provisioned concurrency or multi-region.
16. Architecture decision checklist
- Write the user journey in five bullets with no AWS names.
- Mark each step sync (user waits) or async.
- Name failure mode: retry, DLQ, compensate, or alert-only.
- Name the idempotency key for every write.
- Pick data store from access patterns (link DynamoDB modeling).
- Estimate monthly cost at 1x and 10x traffic (USD and INR).
- Confirm account concurrency and service quotas in ap-south-1.
- Decide auth: Cognito, IAM, Lambda authorizer, or none.
- Name on-call and which CloudWatch alarm pages them.
- Link the deep chapter you will not rewrite.
- 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)
| Term | Meaning |
|---|---|
| Cold start | First invoke pays init; later invokes reuse the env |
| Idempotency | Same request twice → same effect |
| DLQ | Dead-letter queue for failed messages |
| Choreography | Services react to events; no central conductor |
| Orchestration | Central workflow (Step Functions) directs steps |
| Fan-out | One event → many consumers |
| Fan-in | Many branches join before next step |
| Strangler fig | Peel routes from monolith gradually |
| Saga | Distributed tx via steps + compensations |
| Provisioned concurrency | Keep N envs warm; you pay for ready capacity |
20. Practice: explain out loud
- 60 seconds: everyday story for serverless cost quotas.
- 60 seconds: sync vs async with a checkout example.
- 60 seconds: when you refuse Lambda.
- 60 seconds: DLQ + idempotency in one breath.
- 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.
22. How this chapter links others
- Compute depth: Lambda.
- HTTP edge: API Gateway.
- Data modeling: DynamoDB.
- Messaging: SQS/SNS.
- Events: EventBridge.
- Workflows: Step Functions.
- Project chapters (build-*): worked assemblies — link, do not paste.
23. Myths to drop
| Myth | Reality |
|---|---|
| Serverless means zero servers | Servers exist; you do not manage them |
| Always cheaper than EC2 | Steady high load can favor EC2/Savings Plans |
| No Ops needed | You own IAM, data, alarms, cost, incidents |
| One Lambda per app is fine | Bounded contexts scale better |
| Queues are optional decoration | Queues 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.
- Write two SLOs: money-correct and notify-delivered.
- Retries on money path: bounded + idempotent.
- Retries on notify path: best-effort + DLQ.
- 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)
- Imagine tomorrow headline: double charge in AED. What broke?
- Imagine DLQ depth 50,000 after a bad deploy. How do you drain?
- Imagine Cognito outage. Do APIs fail closed or serve read-only?
- 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)
- Rohan models Diwali 10x checkout.
- Service Quotas show concurrent too low.
- Request increase + reserved concurrency on pay.
- 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.








More cards: Ravi Sir's Cards.
Practice Tasks
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.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy GB-seconds matter — 1
Why: Idea.
What to do: Enter 1 if duration GB-seconds drive Lambda cost.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Log retention cost — 1
Why: Idea.
What to do: Enter 1 if forever log retention raises cost risk.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Quotas are limits — 1
Why: Idea.
What to do: Enter 1 if Service Quotas are account/region limits.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Model 10x — 1
Why: Idea.
What to do: Enter 1 if you should model 1x and 10x traffic.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Count retries — 1
Why: Idea.
What to do: Enter 1 if cost models must count retries.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- 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.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Reserved concurrency — 1
Why: Idea.
What to do: Enter 1 if reserved concurrency protects critical functions.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Budget alarm — 1
Why: Idea.
What to do: Enter 1 if AWS Budgets alarms catch spend early.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Self-trigger loop — 1
Why: Idea.
What to do: Enter 1 if a Lambda re-trigger loop can explode cost.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Provisioned costs — 1
Why: Idea.
What to do: Enter 1 if provisioned concurrency bills warm environments.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Throttle on limit — 1
Why: Idea.
What to do: Enter 1 if hitting concurrent limits throttles users.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Cost model keys
Why: Sheet.
What to do: YAML: invokes: 1000000 and gbs: 400000 for a sketch.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Medium Lambda account settings
Why: Concurrency.
What to do: Get Lambda account settings
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- 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.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Null retention bad — 1
Why: Idea.
What to do: Enter 1 if null log retention means keep forever.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.