Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Defying Serverless Constraints: Real-life Serve...

Defying Serverless Constraints: Real-life Serverless Workarounds

Discover practical solutions to real-world serverless constraints faced by engineering teams that builds API projects using popular patterns such as Micro-Lambdas, Lambdaliths and Moduliths. This presentation explores creative workarounds for common and rarely discussed limitations.

Allan Chua

February 21, 2025
Tweet

More Decks by Allan Chua

Other Decks in Programming

Transcript

  1. About Me • Serverless Since 2019 • 4 AWS Certs

    • AWS Community Builders • AWS Singapore UG Volunteer • CTO @ Premier Fiduciary
  2. Micro-Lambdas API Gateway GET /INVOICES GET /INVOICES/{ID} POST /INVOICES/{ID} GET

    /PAYMENTS GET /PAYMENTS/{ID} POST /PAYMENTS/{ID} Single purpose functions that serves requests for a single REST endpoint. • Least Change Collisions on Code • Easier to Maintain • Easiest to Debug • Good for Small Apps and POCs PROS • Most Change Collisions on SAM file • Death by YAML • Plenty of Short Cold Starts • Scaling Constraints CONS
  3. 5 API Gateway CF Resources (Stage, Deployment, Rest API, Domain

    Name, Path Mapping) Maximum # of APIs built on top of Micro-Lambdas per CF Stack ((500 – 5) / 3) = 165 Lambda Functions 1 API Function = 3 Resources 500 Max Resource Count
  4. It used to be lower back @ 2019 LLMs are

    not mainstream during this period ((200 – 5) / 3) = 65 Functions for APIs
  5. Max # of Resources Inside a Cloud Formation Stack Solutioning

    Options Refactor to Lambda-Lith Group Resources into Nested CF Stacks Split Resources into Logical Stacks Go back to Docker and K8s
  6. Splitting Resources into Logical Groups Reactors/ BG Workers Lambda Functions

    APIs Lambda Functions API Gateway Core S3 SQS DynamoDB IAM Roles Do! Core, Reactors, BG Workers and APIs S3 SQS DynamoDB IAM Roles Don’t Lambda Functions API Gateway
  7. Reactors/ BG Workers Lambda Functions APIs Lambda Functions API Gateway

    Core S3 SQS DynamoDB IAM Roles This is decent but… • Scaling Bottleneck at the Compute Stack CONS • Larger Max Resource Constraint • Faster Deployments • Makes Compute Layer Refactorable • Less Risk of Deleting DBs PROS
  8. Dillussional Solution Reactors/ BG Workers Lambda Functions Core S3 SQS

    DynamoDB IAM Roles Notification APIs API Gateway Payment APIs Invoicing APIs Billing APIs Auth APIs Notification APIs
  9. Nesting CloudFormation Stacks Superior Option for Scaling Reactors/ BG Workers

    Lambda Functions Payment APIs API Gateway Core S3 SQS DynamoDB IAM Roles Invoicing APIs API Gateway Auth APIs API Gateway Notification APIs API Gateway Correspondence APIs API Gateway Company APIs API Gateway
  10. Maximum Number of API Gateways Accurate as of Feb 19,

    2025 ACCOUNT-LEVEL | NON-ADJUSTABLE 600 Regional 120 Edge-optimized
  11. Routes per API Gateway GATEWAY-LEVEL | SOFT LIMIT Accurate as

    of Feb 19, 2025 300 36K Edge Optimized APIs 180K Edge Optimized APIs
  12. Maximum Number of IAM Roles per Account ACCOUNT-LEVEL Accurate as

    of Feb 19, 2025 1000 SOFT LIMIT 5000 HARD LIMIT
  13. Max # of API Gateways, IAM Roles, SAM Issues Solutioning

    Options Refactor to Lambda-Lith Merge APIs (Bounded Context) Go back to Docker and K8s
  14. Lambda-Lith GET /INVOICES GET /INVOICES/{ID} POST /INVOICES/{ID} POST /PAYMENTS/{ID} GET

    /PAYMENTS/{ID} GET /PAYMENTS https://middy.js.org/ https://hono.dev/ API Gateway ANY /{proxy+} GREEDY PATH Just like our traditional APIs where a single server process is in-charge of responding to all endpoints in a REST API.
  15. API Routing Frameworks for AWS Lambda - AWESOME for strangler

    migrations - Lowest Barrier of Entry - Gets Rid of Micro-lambda Scaling Issues - Least YAML Coding - Faster Deployment - Frequent Warm Starts - Great for Medium-sized Apps PROS - Higher Risk of Breakage - Single Point of Failure - Slower Response Times - Harder to Debug - Heavy Cold Start - Simple CRUD functions have to be loaded with SDKs used by Reporting APIs - Scaling Issues CONS
  16. Modu-Lith API Gateway ANY /PAYMENTS/{proxy+} ANY /INVOICES/{proxy+} ANY /PURCHASE-ORDERS/{proxy+} -

    Frequent Warm Starts - Awesome for Large-scale API Development - Smaller Blast Radiuses - Low YAML Amount - Low Barrier of Entry - Low IAM Role Count - Simple CRUD APIs don’t need to load heavy SDKs used by reporting APIs PROS - AKA Modular Monoliths - 1 Greedy Path per Module - 1 Function for each Module - Duplicated Libraries Across Functions - Lower amount of code samples & literature CONS ANY /REPORTS/{proxy+} POST /PAYMENTS/{ID} GET /PAYMENTS/{ID} GET /PAYMENTS GET /INVOICES GET /INVOICES/{ID} POST /INVOICES/{ID} GET /PURCHASE-ORDERS GET /PURCHASE-ORDERS/{ID} POST /PURCHASE-ORDERS/{ID} GET /REPORTS GET /REPORTS/{ID} POST /REPORTS/{ID}
  17. Conclusion • Micro-lambdas are great for prototyping. • Spread your

    CF Resources into Logical Groups • Lambda-lith offers low entry barrier to Serverless. • Modulith Offers Extreme Code-base Scaling • Runtimes Expire and Require Routine Upgrades