Serverless Architecture म्हणजे काय? कधी वापरायचं आणि कधी नाही
मित्र चहा स्टॉल ग्राहक आल्यावरच उघडतो. रात्री 3 वाजता रिकाम्या दुकानाचा भाडं नाही. Serverless architecture सॉफ्टवेअरसाठी तीच कल्पना. हा chapter patterns series चा नकाशा — कधी serverless नको तेही सांगतो.
या chapter मध्ये तुम्ही काय शिकाल
- रोजच्या गोष्टीने serverless
- तुम्ही vs AWS
- Lambda vs EC2 vs containers
- Anti-patterns
- Existing chapters link
1. रोजचे उदाहरण: मागणीवरचा चहा स्टॉल
Ravi ऑर्डर आल्यावरच पाणी उकळवतो. Priya (Bengaluru) PDF invoice API तशीच. Always-on EC2 रात्री वाया. API Gateway+Lambda per invoice उठते. हेच serverless architecture.
Serverless = servers नाहीत नव्हे. Servers AWS मध्ये. SSH/patch/fleet तुमचे काम नाही.
पूर्ण system आधी What Is AWS Lambda? refresh करा. हा chapter architecture.
2. Architecture view का?
हे का लागतं?
पाच tutorials = architecture नव्हे. Recursive S3, DLQ नाही, surprise bills. Architecture आधी fit/limits/failure/cost.
हे काय आहे?
Serverless architecture = managed event-driven services + patterns.
| तुम्ही | AWS | उदाहरण |
|---|---|---|
| Code, IAM, data, alarms | Servers, OS, metal | Handler; AWS microVM |
| Retry/DLQ design | Queue replication | maxReceiveCount |
| Auth/WAF/secrets process | KMS/Cognito | Authorizer |
3. Vertical diagram
4. तुम्ही शिकलेले blocks
हे काय आहे?
- Compute: What Is AWS Lambda?.
- HTTP: API Gateway.
- Data: DynamoDB.
- Messaging: SQS and SNS.
- Events: EventBridge.
- Orchestration: Step Functions.
- Identity: Cognito.
Live projects: notes app project, URL shortener. Patterns link — source paste नाही.
5. कधी चमकतं
- Spiky traffic.
- Glue work.
- Small APIs.
- Cron.
- Prototypes.
6. कधी नको
| Smell | Better | का |
|---|---|---|
| 30-120 min job | ECS/Batch/EC2 | 15 min cap |
| Sticky huge mem | ECS/EKS | Stateless |
| <5ms hairpin | Fleet | Cold/VPC |
| Always-warm monolith | ECS | Packaging |
| All-day GPU | EC2/SageMaker | GPU rare |
| Runtime banned | EC2 | GRC |
Ravindra Bagale's Tip
प्रत्येक function ला provisioned concurrency हवं असेल तर always-on container विचार करा.
7. Decision table
| प्रश्न | हो | नाही |
|---|---|---|
| Seconds-minutes? | Lambda | ECS/Batch/EC2 |
| ~0 traffic? | Serverless | Reserved |
| Custom/GPU? | EC2/ECS | Lambda |
| On K8s? | Glue only | Serverless API |
8. Sketch कसा
कसं करायचं (step by step)
- 5 bullets, no AWS names.
- Sync vs async.
- Map sync/async.
- Data from access patterns.
- Auth+observe+failure.
- 10x cost.
- मग console/IaC.
Functions list
aws lambda list-functions --region ap-south-1 --query 'Functions[].FunctionName' --output table
अर्थ: नवीन hello आधी existing बघा.
Concurrency ceiling
aws lambda get-account-settings --region ap-south-1 --query 'AccountLimit.[ConcurrentExecutions,UnreservedConcurrentExecutions]'
अर्थ: Load test आधी ceiling.
9. Lab: कागद + console
Org block नसेल तर ap-south-1 (Mumbai). आधी budget alert.
कसं करायचं (step by step)
- create-order diagram.
- Sync/async + idempotency.
- Dashboard read-only.
- p99 vs timeout.
- एक वाक्य.
Cleanup (billing थांबवा)
- Test function delete.
- आजचे log groups.
10. Mini-examples
Python: async?
def prefer_async(user_waits, work_ms):
if not user_waits: return True
return work_ms > 2500
print(prefer_async(True, 800))
print(prefer_async(True, 8000))
print(prefer_async(False, 100))
Output: False/True/True. अर्थ: लांब wait = queue.
Node: GB-seconds
const gbSec=(mb,ms,n)=>(mb/1024)*(ms/1000)*n;
console.log(gbSec(512,200,1_000_000)); // 100000
अर्थ: ≈100k GB-s. Pricing page बघा.
11. Stack stories
- FastAPI peel /invoices.
- Node bounded context.
- Java -> ECS via Lambda.
- .NET on Lambda.
- Go ESM.
- PHP hybrid.
12. Commands + meaning
Function timeout
aws lambda get-function-configuration --function-name hello-lambda-lab --region ap-south-1 --query '[Timeout,MemorySize]'
अर्थ: Timeout vs p99.
Log groups
aws logs describe-log-groups --log-group-name-prefix /aws/lambda/ --region ap-south-1 --max-items 5
अर्थ: Logs कुठे पडतात ते बघा.
13. एकाच pattern — वेगवेगळ्या industries
- Fintech (Aisha, Lagos): payment webhooks → SQS → Lambda.
- Ecommerce (Rohan, Pune): checkout API; inventory SNS fan-out.
- Healthcare (Mei, Singapore): SNS SMS; PHI + fine-grained IAM.
- EdTech (Diego, São Paulo): EventBridge nightly cleanup.
- Logistics (Fatima, Casablanca): EventBridge + saga.
- Media (Kenji, Osaka): S3 → Lambda thumbs + fan-out.
- SaaS (Priya, Bengaluru): Cognito + per-tenant partition.
- Gov (Omar, Amman): strangler fig per form route.
14. Troubleshooting checklist
- Region confirm करा.
- CloudWatch Logs + request id.
- Execution role permissions.
- DLQ + oldest message age.
- curl -v + CORS.
- SFN event history.
- Linked chapter पुन्हा वाचा.
- Cost: concurrency/retries.
15. सामान्य errors आणि fixes
प्रत्येक row = खरी चूक. Panic करण्याआधी fix वाचा.
| Error / लक्षण | Fix |
|---|---|
| एकच मोठी Lambda | Split. |
| DLQ नाही | DLQ. |
| Recursive S3 | वेगळा prefix. |
| Encode in Lambda | MediaConvert. |
| Cron+provisioned | On-demand. |
| Secrets in env | Secrets Manager. |
| Concurrency ignore | Load test. |
| DDB copy | Link. |
| No-Ops | Still Ops. |
| Big-bang | Strangler. |
16. FAQ
प्र. फक्त Lambda?
नाही.
प्र. नेहमी स्वस्त?
नाही.
प्र. Laravel?
Strangler.
प्र. Cold starts?
Later chapter.
प्र. Projects?
Link.
प्र. आधी K8s?
नाही.
17. Interview Q&A (Beginner / Mid / Senior + MNC)
प्र. Beginner
On-demand; servers exist.
प्र. पाच blocks
Lambda APIGW DDB SQS EB.
प्र. Mid refuse
Long/sticky/latency.
प्र. Sync/async
Wait=sync.
प्र. Senior bills
Budgets+caps.
प्र. MNC
SQS+idempotent+saga.
18. Tips — English, मराठी आणि हिंदी
Ravindra Bagale's Tip (EN)
Draw the vertical path on paper before the console. Missing boxes become hidden servers.
Ravindra Bagale's Tip (MR)
Console आधी कागदावर vertical path. गायब box = hidden server.
Tip (HI)
कंसोल से पहले कागज़ पर vertical path बनाएं। छूटा बॉक्स hidden server बनता है।
घरी करून बघा
- ADR लिहा.
- तीन anti-fits.
थोडक्यात सांगायचं तर
- गोष्टी पासून सुरू, मग services.
- Existing chapters link — labs copy नको.
- Failure साठी design.
- Measure → मग पैसे.
19. Code आधी cost gut-check
Priya receipt API: 2M invokes, 256MB, 150ms. GB-s ≈ 75k. Free tier शक्य; APIGW+DDB वेगळे. ap-south-1 pricing page बघा.
Python: rough compute
def gb_seconds(mb, ms, invokes):
return (mb/1024.0) * (ms/1000.0) * invokes
print(round(gb_seconds(256, 150, 2_000_000)))
print(round(gb_seconds(1024, 3000, 100_000)))
Output: 75000 / 300000. अर्थ: memory+duration > फक्त invoke count.
20. Failure paths
हे काय आहे?
- Sync: stable JSON errors.
- Async: DLQ + alarm.
- Fan-out partial fail.
- SFN retries + compensate.
- Auth at edge.
21. Observability starter
- JSON logs + requestId.
- Business metric.
- Alarms.
- X-Ray/Powertools later.
Log streams
aws logs describe-log-streams --log-group-name /aws/lambda/hello-lambda-lab \
--order-by LastEventTime --descending --max-items 3 --region ap-south-1
अर्थ: Insights आधी logs येतात का ते बघा.
22. Anti-pattern deep dive
| Anti-pattern | लक्षण | Fix |
|---|---|---|
| Sync Lambda→Lambda | Timeouts + cost | SQS/EB between |
| /tmp as DB | Collisions | DDB/S3 |
| Fat zip | Slow cold | Layers/image |
| One role | Blast radius | Per-function IAM |
| No reserved | Starvation | Reserve/limit |
23. Migration sketch
Weekend rewrite नको. Strangler chapter: APIGW front, एक route peel. आज: पहिला peel candidate लिहा.
- Top 10 routes.
- Low shared state.
- Read-heavy peel #1.
- Metrics आधी.
24. पहिल्या production cut साठी checklist
- Budget + anomaly.
- IAM second review.
- DLQ + alarm.
- Runbook in alarm.
- Load test 2x.
- Rollback alias.
- PITR if money/PII.
- when-NOT documented.
दोन missing असतील तर अजून lab — production म्हणू नका.
25. Architecture decision checklist
- User journey 5 bullets, no AWS names.
- Sync vs async mark.
- Failure mode.
- Idempotency key.
- Data from access patterns.
- Cost 1x and 10x.
- Quotas ap-south-1.
- Auth decision.
- On-call + alarm.
- Deep chapter link.
- मग console/IaC.
26. Copy-paste quick commands
# 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
Sandbox + read-only IAM.
27. अजून industry आणि stack stories
- Fintech Lagos: webhook → SQS → idempotent ledger.
- Ecommerce Pune: throttle + fan-out.
- Healthcare SG: SNS + PHI IAM.
- EdTech: EventBridge cleanup.
- Logistics: bus + saga.
- Media: avoid recursive S3.
- SaaS: tenant partition.
- Gov: strangler peel.
- Startup: Function URL → HTTP API.
- Retail: FIFO vs Standard.
- Python: thin handlers.
- Node: async/await.
- Java: SnapStart.
- .NET: package size.
- Go: static binary.
- PHP: hybrid.
28. Glossary
| Term | अर्थ |
|---|---|
| Cold start | पहिल्या invoke ची init |
| Idempotency | दोनदा = तोच effect |
| DLQ | Fail झालेले messages |
| Choreography | Events; conductor नाही |
| Orchestration | SFN central |
| Fan-out | एक → अनेक |
| Fan-in | अनेक → join |
| Strangler fig | Monolith peel |
| Saga | Steps + compensate |
| Provisioned concurrency | Warm N; pay |
29. Practice: मोठ्याने explain
- 60s: serverless architecture गोष्ट.
- 60s: sync vs async checkout.
- 60s: Lambda नको कधी.
- 60s: DLQ + idempotency.
- Record ×2.
30. Safe lab hygiene
- Tag owner+expiry.
- Budget alarm आधी.
- Read-only first.
- Cleanup.
- No secrets in env/screenshots.
- No provisioned on hello.
31. या chapter च्या links
- Compute: Lambda.
- HTTP: API Gateway.
- Data: DynamoDB.
- Messaging: SQS/SNS.
- Events: EventBridge.
- Workflows: Step Functions.
- build-* projects link.
32. Myths
| Myth | खरं |
|---|---|
| Servers नाहीत | Servers आहेत; manage नको |
| नेहमी स्वस्त | Steady वर EC2 |
| No Ops | IAM/data/alarms |
| एक Lambda | Bounded contexts |
| Queues optional | Load leveler |
33. Serverless error budget
Checkout error budget 0.1% असेल तर aggressive retries email duplicates देऊन budget जाळू शकतात. Money SLO ≠ notify SLO.
- दोन SLOs.
- Money retries bounded.
- Notify best-effort.
- Money page; notify ticket.
34. Regional notes (ap-south-1)
- Labs Mumbai.
- Feature availability.
- Data residency.
- Latency India.
35. Naming conventions
# 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
env + domain नावात ठेवा. CloudWatch grep सोपा.
36. Pre-mortems
- Double charge headline.
- DLQ drain plan.
- Cognito outage mode.
- Runbook.
37. Currency / locale
Currencies आणि names rotate करा — global mental model.
उजळणी, मुलाखत आणि तुलना cards
हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.








अजून cards: Ravi Sir's Cards.
सराव Tasks
Maple Leaf Books हा टोरांटो मधला पुस्तक विक्री व्यवसाय आहे. Emily Tremblay त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे CAD मध्ये मोजले जातात आणि AWS resources ca-central-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.
0 / 16
सोपं Servers
का: Model.
काय करायचं: Servers exist तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं On-demand
का: Fit.
काय करायचं: On-demand तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं 15 min
का: Limit.
काय करायचं: 15 minutes तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं Long job
का: Fit.
काय करायचं: Long job ECS तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं List
का: CLI.
काय करायचं: list.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
सोपं Fit YAML
का: Keys.
काय करायचं: timeout_ok / stateful.
- Task मधल्या top-level keys पासून सुरू करा.
- Child keys 2 spaces ने indent करा (tabs नकोत).
- प्रत्येक property मध्ये task मधली value भरा.
- Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.
सोपं Cold
का: Reality.
काय करायचं: Cold start तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम Sync
का: UX.
काय करायचं: User waits तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम Concurrency
का: Shared.
काय करायचं: Shared limit तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम PC
का: Cost.
काय करायचं: Wasteful PC तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम Loop
का: Anti.
काय करायचं: Infinite loop तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम When not
का: Anti.
काय करायचं: long_job / always_on.
- Task मधल्या top-level keys पासून सुरू करा.
- Child keys 2 spaces ने indent करा (tabs नकोत).
- प्रत्येक property मध्ये task मधली value भरा.
- Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.
अवघड Fit
का: Design.
काय करायचं: Fit first तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
अवघड Bare
का: Scope.
काय करायचं: Not bare-metal तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
अवघड Billing
का: Model.
काय करायचं: Pay per use तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
अवघड Lab
का: Hygiene.
काय करायचं: Delete lab तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.