Slide 1

Slide 1 text

Defying Serverless Constraints Real-life Serverless Workarounds Allan Chua Feb 2025 L400 | Serverless | AWS Singapore User Group

Slide 2

Slide 2 text

About Me • Serverless Since 2019 • 4 AWS Certs • AWS Community Builders • AWS Singapore UG Volunteer • CTO @ Premier Fiduciary

Slide 3

Slide 3 text

Code Samples https://github.com/allanchua101/defying-serverless-constraints-demo

Slide 4

Slide 4 text

This Presentation is About Serverless API Archetypes Constraints Solutioning Options Pros & Cons Analysis

Slide 5

Slide 5 text

What’s Covered AWS Lambda API Gateway SAM Rest APIs Cloud Formation Node JS

Slide 6

Slide 6 text

What’s Not Covered Event-Driven Architecture (EDA) TypeScript Storage Services

Slide 7

Slide 7 text

Serverless API Archetypes

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

Maximum Number of Resources Inside a Cloud Formation Stack 500 Accurate as of Feb 19, 2025

Slide 10

Slide 10 text

Gateway-Lambda Integration Anatomy Input Output Lambda Function Function Execution Role Function Invocation Permission

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

It used to be lower back @ 2019 LLMs are not mainstream during this period ((200 – 5) / 3) = 65 Functions for APIs

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

But You Can't Reference API Gateways from another CloudFormation Stack when using SAM Problem since 2018

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Maximum Number of API Gateways Accurate as of Feb 19, 2025 ACCOUNT-LEVEL | NON-ADJUSTABLE 600 Regional 120 Edge-optimized

Slide 20

Slide 20 text

Routes per API Gateway GATEWAY-LEVEL | SOFT LIMIT Accurate as of Feb 19, 2025 300 36K Edge Optimized APIs 180K Edge Optimized APIs

Slide 21

Slide 21 text

Maximum Number of IAM Roles per Account ACCOUNT-LEVEL Accurate as of Feb 19, 2025 1000 SOFT LIMIT 5000 HARD LIMIT

Slide 22

Slide 22 text

AWS Service Quotas Are Adjustable They are Not Portable

Slide 23

Slide 23 text

AWS Service Quotas Are Adjustable But Not Portable DEV UAT PRD “It Works in my Account“

Slide 24

Slide 24 text

Max # of API Gateways, IAM Roles, SAM Issues Solutioning Options Refactor to Lambda-Lith Merge APIs (Bounded Context) Go back to Docker and K8s

Slide 25

Slide 25 text

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.

Slide 26

Slide 26 text

https://middy.js.org/ Middy

Slide 27

Slide 27 text

https://hono.dev/ HONO

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Lambda Function Maximum Package Size (Zipped) FUNCTION-LEVEL | HARD-LIMIT Accurate as of Feb 19, 2025 50 MB

Slide 30

Slide 30 text

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}

Slide 31

Slide 31 text

Runtime Lifespan

Slide 32

Slide 32 text

Serverless Ops Myth “AWS will take care of trivial Ops work for my Lambda Functions”

Slide 33

Slide 33 text

Upgrading Function Runtimes Consumes Manpower Responsibility is Shared

Slide 34

Slide 34 text

NodeJS Runtime Calendar http://bit.ly/42X2cPW

Slide 35

Slide 35 text

NodeJS Runtime Block Function Creation Calendar Feb 2025 16 Oct 2025 18 Jun 2026 20 22 Jun 2027

Slide 36

Slide 36 text

Function Runtime Upgrades and Monitoring Required https://allanchua101.github.io/sana/

Slide 37

Slide 37 text

Helps you monitor function upgrade progress

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

5 Minutes Q&A Session

Slide 40

Slide 40 text

Feedback