Ravindra BagaleCourses & study guides English Track your progress

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, alarmsServers, OS, metalHandler; AWS microVM
Retry/DLQ designQueue replicationmaxReceiveCount
Auth/WAF/secrets processKMS/CognitoAuthorizer

3. Vertical diagram

Client -> API -> Lambda -> Bus -> Workers -> DataSync जलद; async level
Box चुकले = hidden servers
Client API Gateway / Function URL Lambda / Step Functions SQS / SNS / EventBridge Worker Lambdas DynamoDB / S3 Observe later: Logs + X-Ray + alarms
बहुतेक serverless systems साठी vertical path.

4. तुम्ही शिकलेले blocks

हे काय आहे?

Live projects: notes app project, URL shortener. Patterns link — source paste नाही.

5. कधी चमकतं

  • Spiky traffic.
  • Glue work.
  • Small APIs.
  • Cron.
  • Prototypes.

6. कधी नको

SmellBetterका
30-120 min jobECS/Batch/EC215 min cap
Sticky huge memECS/EKSStateless
<5ms hairpinFleetCold/VPC
Always-warm monolithECSPackaging
All-day GPUEC2/SageMakerGPU rare
Runtime bannedEC2GRC

Ravindra Bagale's Tip

प्रत्येक function ला provisioned concurrency हवं असेल तर always-on container विचार करा.

7. Decision table

प्रश्नहोनाही
Seconds-minutes?LambdaECS/Batch/EC2
~0 traffic?ServerlessReserved
Custom/GPU?EC2/ECSLambda
On K8s?Glue onlyServerless API

8. Sketch कसा

कसं करायचं (step by step)

  1. 5 bullets, no AWS names.
  2. Sync vs async.
  3. Map sync/async.
  4. Data from access patterns.
  5. Auth+observe+failure.
  6. 10x cost.
  7. मग 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)

  1. create-order diagram.
  2. Sync/async + idempotency.
  3. Dashboard read-only.
  4. p99 vs timeout.
  5. एक वाक्य.

Cleanup (billing थांबवा)

  1. Test function delete.
  2. आजचे 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

  1. FastAPI peel /invoices.
  2. Node bounded context.
  3. Java -> ECS via Lambda.
  4. .NET on Lambda.
  5. Go ESM.
  6. 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

  1. Region confirm करा.
  2. CloudWatch Logs + request id.
  3. Execution role permissions.
  4. DLQ + oldest message age.
  5. curl -v + CORS.
  6. SFN event history.
  7. Linked chapter पुन्हा वाचा.
  8. Cost: concurrency/retries.

15. सामान्य errors आणि fixes

प्रत्येक row = खरी चूक. Panic करण्याआधी fix वाचा.

Error / लक्षणFix
एकच मोठी LambdaSplit.
DLQ नाहीDLQ.
Recursive S3वेगळा prefix.
Encode in LambdaMediaConvert.
Cron+provisionedOn-demand.
Secrets in envSecrets Manager.
Concurrency ignoreLoad test.
DDB copyLink.
No-OpsStill Ops.
Big-bangStrangler.

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 बनता है।

घरी करून बघा

  1. ADR लिहा.
  2. तीन anti-fits.

थोडक्यात सांगायचं तर

  1. गोष्टी पासून सुरू, मग services.
  2. Existing chapters link — labs copy नको.
  3. Failure साठी design.
  4. 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

हे काय आहे?

  1. Sync: stable JSON errors.
  2. Async: DLQ + alarm.
  3. Fan-out partial fail.
  4. SFN retries + compensate.
  5. 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→LambdaTimeouts + costSQS/EB between
/tmp as DBCollisionsDDB/S3
Fat zipSlow coldLayers/image
One roleBlast radiusPer-function IAM
No reservedStarvationReserve/limit

23. Migration sketch

Weekend rewrite नको. Strangler chapter: APIGW front, एक route peel. आज: पहिला peel candidate लिहा.

  1. Top 10 routes.
  2. Low shared state.
  3. Read-heavy peel #1.
  4. Metrics आधी.

24. पहिल्या production cut साठी checklist

  1. Budget + anomaly.
  2. IAM second review.
  3. DLQ + alarm.
  4. Runbook in alarm.
  5. Load test 2x.
  6. Rollback alias.
  7. PITR if money/PII.
  8. when-NOT documented.

दोन missing असतील तर अजून lab — production म्हणू नका.

25. Architecture decision checklist

  1. User journey 5 bullets, no AWS names.
  2. Sync vs async mark.
  3. Failure mode.
  4. Idempotency key.
  5. Data from access patterns.
  6. Cost 1x and 10x.
  7. Quotas ap-south-1.
  8. Auth decision.
  9. On-call + alarm.
  10. Deep chapter link.
  11. मग 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
DLQFail झालेले messages
ChoreographyEvents; conductor नाही
OrchestrationSFN central
Fan-outएक → अनेक
Fan-inअनेक → join
Strangler figMonolith peel
SagaSteps + compensate
Provisioned concurrencyWarm N; pay

29. Practice: मोठ्याने explain

  1. 60s: serverless architecture गोष्ट.
  2. 60s: sync vs async checkout.
  3. 60s: Lambda नको कधी.
  4. 60s: DLQ + idempotency.
  5. Record ×2.

30. Safe lab hygiene

  • Tag owner+expiry.
  • Budget alarm आधी.
  • Read-only first.
  • Cleanup.
  • No secrets in env/screenshots.
  • No provisioned on hello.

32. Myths

Mythखरं
Servers नाहीतServers आहेत; manage नको
नेहमी स्वस्तSteady वर EC2
No OpsIAM/data/alarms
एक LambdaBounded contexts
Queues optionalLoad leveler

33. Serverless error budget

Checkout error budget 0.1% असेल तर aggressive retries email duplicates देऊन budget जाळू शकतात. Money SLO ≠ notify SLO.

  1. दोन SLOs.
  2. Money retries bounded.
  3. Notify best-effort.
  4. 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

  1. Double charge headline.
  2. DLQ drain plan.
  3. Cognito outage mode.
  4. Runbook.

37. Currency / locale

Currencies आणि names rotate करा — global mental model.

उजळणी, मुलाखत आणि तुलना cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

उजळणी card: Fit before code. आधी Lambda → नंतर surprises. Fit, sync/async, timeout, concurrency, cost. Path → limit → sync/queue → RPS. Paper first.
उजळणी card: Fit before code · PNG download करा · Card page उघडा
उजळणी card: When not serverless. Force-fit hurts. Long / sticky / always-on → other compute. Length → state → choose. Encode off Lambda.
उजळणी card: When not serverless · PNG download करा · Card page उघडा
तुलना: Lambda vs ECS/Batch. Lambda: Minutes-or-less. ECS/Batch: Long / sticky / always-on.
तुलना: Lambda vs ECS/Batch · PNG download करा · Card page उघडा
तुलना: Sync path vs Async queue. Sync path: Wait now. Async queue: 202 later.
तुलना: Sync path vs Async queue · PNG download करा · Card page उघडा
मुलाखत card: Lambda timeout. 15-min ceiling. 15 min → other compute. Ceiling + escape.
मुलाखत card: Lambda timeout · PNG download करा · Card page उघडा
मुलाखत card: Account concurrency. Noisy neighbor. Reserve + watch. Reserved vs PC.
मुलाखत card: Account concurrency · PNG download करा · Card page उघडा
मुलाखत card: Cold starts. p99 surprise. Measure → trim → PC if needed. When PC pays.
मुलाखत card: Cold starts · PNG download करा · Card page उघडा
मुलाखत card: Fit checklist. Code-first trap. Duration/state/traffic/fail/cost. Chai-stall fit.
मुलाखत card: Fit checklist · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.

सराव Tasks

या scenario बद्दल

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.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं On-demand

का: Fit.

काय करायचं: On-demand तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं 15 min

का: Limit.

काय करायचं: 15 minutes तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Long job

का: Fit.

काय करायचं: Long job ECS तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं List

का: CLI.

काय करायचं: list.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं Fit YAML

का: Keys.

काय करायचं: timeout_ok / stateful.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

सोपं Cold

का: Reality.

काय करायचं: Cold start तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Sync

का: UX.

काय करायचं: User waits तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Concurrency

का: Shared.

काय करायचं: Shared limit तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम PC

का: Cost.

काय करायचं: Wasteful PC तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Loop

का: Anti.

काय करायचं: Infinite loop तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम When not

का: Anti.

काय करायचं: long_job / always_on.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

अवघड Fit

का: Design.

काय करायचं: Fit first तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Bare

का: Scope.

काय करायचं: Not bare-metal तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Billing

का: Model.

काय करायचं: Pay per use तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

अवघड Lab

का: Hygiene.

काय करायचं: Delete lab तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.