SlideShare a Scribd company logo
Building Resilient Serverless Systems
with Non-Serverless Components
Jeremy Daly
CTO, AlertMe.news
@jeremy_daly
Jeremy Daly
• CTO at AlertMe.news
• Consult with companies building in the cloud
• 20+ year veteran of technology startups
• Started working with AWS in 2009 and started using
Lambda in 2015
• Blogger (jeremydaly.com), OSS contributor, speaker
• Publish the Off-by-none serverless newsletter
• Host of the Serverless Chats podcast
@jeremy_daly
Agenda
• What is resiliency and what is serverless?
• Working with “less-than-scalable” RDBMS
• Using unreliable APIs
• Managing API quotas
• Decoupling our services
• Other non-serverless components
@jeremy_daly
What is resiliency?
@jeremy_daly
“The ability of a software solution to absorb the impact
of a problem in one or more parts of a system, while
continuing to provide an acceptable service level to the
business.” ~ IBM
IT’S NOT ABOUT PREVENTING FAILURE
IT’S UNDERSTANDING HOWTO GRACEFULLY DEAL WITH IT
What does it mean to be Serverless?
• No server management
• Flexible scaling
• Pay for value
• Automated high availability
@jeremy_daly
Flexible scaling 👈
What does it mean to be Serverless?
@jeremy_daly
ElastiCache
RDS
EMR Amazon ES
Redshift
Fargate
Anything “on EC2”Lambda Cognito Kinesis
S3 DynamoDB SQS
SNS API Gateway CloudWatch
AppSync IoT Comprehend
Serverless Managed Not Serverless
DocumentDB
(MongoDB)
Managed Streaming
for Kaca
Definitely
Everything has limits!
• Reserved Concurrency 🚦
• FunctionTimeouts ⏳
• Memory Limits 🧠
• NetworkThroughput 🚰
Some components are better than others
@jeremy_daly
Know
Your
Limits
Simple ServerlessWeb Service
Client
API Gateway Lambda DynamoDB
@jeremy_daly
Highly Scalable Highly Scalable Highly Scalable
“I want my, I want my, I want my SQL”
~ Dire Straits
Simple ServerlessWeb Service
Client
API Gateway Lambda
@jeremy_daly
Highly Scalable Highly Scalable NotThat Scalable 😳
RDS
^
not so
RDBMS and FaaS don’t play nicely together:
• Concurrency model doesn’t allow connection pooling
• Limited number of DB connections available
• Recycled containers create zombies
Ways to Manage DB Connections
• Increase max_connections setting
• Limit concurrent executions
• Lower your connection timeouts
• Limit connections per username
• Close connection before function ends
@jeremy_daly
🤞
😡
⚠
🎲
😱
👎
BetterWays to Manage DB Connections
• Implement a good caching strategy 💾
• Buffer events for throttling and durability 🏋
• Utilize a proxy service 🛰
• Manage connections ourselves 🤔
@jeremy_daly
👎
miss
Implement a good caching strategy
Client API Gateway RDSLambda
Elasticache
Key Points:
• Create new RDS connections ONLY on misses
• Make sureTTLs are set appropriately
• Include the ability to invalidate cache
@jeremy_daly
YOU STILL NEEDTO
SIZEYOUR DATABASE
CLUSTERS APPROPRIATELY
Do you really need immediate feedback?
Synchronous Communication
Services can be invoked by other services and must wait for a reply.
This is considered a blocking request, because the invoking service
cannot finish executing until a response is received.
Asynchronous Communication 🚀
This is a non-blocking request. A service can invoke (or trigger)
another service directly or it can use another type of communication
channel to queue information.The service typically only needs to wait
for confirmation (ack) that the request was received.
@jeremy_daly
RDS
Buffer events for throttling and durability
Client API Gateway
SQS
Queue
SQS
(DLQ)
Lambda Lambda
(throttled)
ack
“Asynchronous”
Request
Synchronous
Request
@jeremy_daly
Key Points:
• SQS adds durability
• Throttled Lambdas reduce downstream pressure
• Failed events are stored for further inspection/replay
Limit the
concurrency to match
RDS throughput
x
Utilize Service
Integrations
Utilize a Proxy Service
• PgBouncer 🏀
• SQL Relay 🏃
@jeremy_daly
Client
API
Gateway
Lambda RDSEC2x
Fargate
🙀
• Amazon RDS Proxy (Preview)
In a “serverless” application?
FOR SHAME! 😿
Manage connections ourselves
1. Count open connections
2. Close connection if connection ratio threshold exceeded
3. Close sleeping connections with high time values
4. Retry connections with exponential back off
@jeremy_daly
Serverless MySQL
https://github.com/jeremydaly/serverless-mysql
@jeremy_daly
Count open connections
@jeremy_daly
Query the
processlist to get
the total number
of active
connections
Close connection if over ratio threshold
@jeremy_daly
If we exceed the
connection ratio
Calculate our timeout
Try to kill zombies
If no zombies,
terminate connection
Else, just try to kill
zombies
Close sleeping connections with high time values
@jeremy_daly
Query processlist for zombies
Kill zombies
Retry connections with exponential back off
@jeremy_daly
If error trying to connect
Retry with Jitter
Does this really work?
@jeremy_daly
• Aurora Serverless (2 ACUs)
• 90 connections available
• 1,024 MB of memory
• 500 users/sec for one minute
• Avg. response time was 41 ms
• ZERO ERRORS
We shouldn’t have to do this!
@jeremy_daly
Amazon
Aurora Serverless
Aurora Serverless
DATA API
Doesn’t solve the
max_connections issue
Slower throughput, not quite
ready for synchronous workloads
Amazon
RDS Proxy
Added cost, still doesn’t
address scalability issues
*PREVIEW*
🥰
Third-Party APIs
Manage calls to third-party APIs
• Implement a good caching strategy 💾
• Buffer events for throttling and durability 🏋
• Implement circuit breakers 🚦
@jeremy_daly
DynamoDB
Stripe API
The Circuit Breaker
Client API Gateway Lambda
Key Points:
• Cache your cache with warm functions
• Use a reasonable failure count
• Understand idempotency
Status
Check CLOSED
OPEN
Increment Failure Count
HALF OPEN
“Everything fails all the time.”
~WernerVogels
@jeremy_daly
🔥
🔥
🔥
🔥
🔥
Elasticache
or
What about quotas?
• Concurrency has no effect on frequency ⏰
• Stateless functions are not coordinated 😿
• Step Functions StandardWorkflows would be very expensive 💰
• Adding state wouldn’t prevent needless invocations 🗑
@jeremy_daly
Can we build a better system?
• 100% serverless
• Cost effective
• Scalable
• Resilient
• Efficient
• Coordinated
@jeremy_daly
Lambda Orchestrator
(concurrency 1)
The Lambda Orchestrator
DynamoDB
LambdaWorker
LambdaWorker
LambdaWorker
Concurrent Executions
of the SAME function
SQS (DLQ)
@jeremy_daly
CloudWatch Rule
(trigger every minute)
SQS QueueSQS (DLQ)
Status?
Gmail API
250 Quota Units
per minute
Decoupling Our Services
Multicasting with SNS
Key Points:
• SNS has a “well-defined API”
• Decouples downstream processes
• Allows multiple subscribers with message filters
Client
SNS
“Asynchronous”
Request
ack
Event Service
@jeremy_daly
HTTP
SMS
Lambda
SQS
Email
SQS (DLQ)
FUN FACT:
SNS to SQS is
“guaranteed”
(100,010 retries)
@jeremy_daly
Multicasting with EventBridge
Key Points:
• Allows multiple subscribers with RULES, PATTERNS and FILTERS
• Forward events to other accounts
• 24 hours of automated retries
Asynchronous
“PutEvents” Request
ack
w/ event id
Amazon
EventBridge
Lambda
SQS
Client
Step Function
Event Bus
+16 others
Key Points:
• Filter events to selectively trigger services
• Manage throttling/quotas per service
• Use Lambda Destinations with asynchronous events
Stripe API
@jeremy_daly
Distribute &Throttle
ack
SQS
Queue Lambda
(concurrency 25)
Client API
Gateway
Lambda
Order Service
"total": [{ "numeric": [ ”>", 0 ]}]
RDS
SQS
Queue Lambda
(concurrency 10)
SMS Alerting Service
Twilio API
SQS
Queue Lambda
(concurrency 5)
Billing Service
"detail-type": [ "ORDER COMPLETE" ]
EventBridge
Other non-serverless components
• Managed Services
• Other cloud services (MongoDB Atlas, ElasticSearch, etc.)
• Legacy Systems
• Our own serverless APIs 🤔
@jeremy_daly
Non-serverless components are inevitable
• Know the limits of your components
• Use a good caching strategy
• Embrace asynchronous processes
• Buffer and throttle events to distributed systems
• Utilize eventual consistency
@jeremy_daly
👈
Things I’m working on…
Blog: JeremyDaly.com
Podcast: ServerlessChats.com
Newsletter: Osynone.io
DDBToolbox: DynamoDBToolbox.com
Lambda API: LambdaAPI.com
GitHub: github.com/jeremydaly
Twitter: @jeremy_daly
@jeremy_daly
ThankYou!
Jeremy Daly
jeremy@jeremydaly.com
@jeremy_daly

More Related Content

PDF
Building resilient serverless systems with non-serverless components (Belfast)
PDF
How to fail with serverless
PDF
Building resilient serverless systems with non-serverless components - Server...
PDF
Building Resilient Serverless Systems with Non-Serverless Components
PDF
Serverless Microservice Patterns for AWS
PDF
Building Event-Driven Applications with Serverless and AWS - AWS Summit New York
PDF
Serverless Security: Best practices and mitigation strategies (re:Inforce 2019)
PDF
Serverless presentation
Building resilient serverless systems with non-serverless components (Belfast)
How to fail with serverless
Building resilient serverless systems with non-serverless components - Server...
Building Resilient Serverless Systems with Non-Serverless Components
Serverless Microservice Patterns for AWS
Building Event-Driven Applications with Serverless and AWS - AWS Summit New York
Serverless Security: Best practices and mitigation strategies (re:Inforce 2019)
Serverless presentation

What's hot (13)

PDF
How LEGO.com Accelerates With Serverless
PDF
Choosing the right messaging service for your serverless app [with lumigo]
PPTX
CQRS Evolved - CQRS + Akka.NET
PDF
A year with event sourcing and CQRS
PDF
Shillings in Serverless
PDF
Thinking Asynchronously Full Vesion - Utah UG
PDF
AWS Lambda
PDF
FaaS or not to FaaS ServerlessDays Tel Aviv 2019
PDF
locize tech stack
PPTX
Jumpstart: Introduction to Atlas, Highlighting Enterprise Features
PPTX
IT Talk «Microservices & Serverless Architectures», Alexander Chichenin (Solu...
PDF
Serverless
PDF
Ruby Conference Belarus 2019 Apr Jets Ruby Serverless Framework
How LEGO.com Accelerates With Serverless
Choosing the right messaging service for your serverless app [with lumigo]
CQRS Evolved - CQRS + Akka.NET
A year with event sourcing and CQRS
Shillings in Serverless
Thinking Asynchronously Full Vesion - Utah UG
AWS Lambda
FaaS or not to FaaS ServerlessDays Tel Aviv 2019
locize tech stack
Jumpstart: Introduction to Atlas, Highlighting Enterprise Features
IT Talk «Microservices & Serverless Architectures», Alexander Chichenin (Solu...
Serverless
Ruby Conference Belarus 2019 Apr Jets Ruby Serverless Framework
Ad

Similar to Building resilient serverless systems with non-serverless components - Cardiff 2020 (20)

PDF
Building resilient serverless systems with non serverless components
PDF
Square Peg Round Hole: Serverless Solutions For Non-Serverless Problems
PDF
Serverless Architectural Patterns
PDF
Serverless Design Patterns
PDF
Serveless Design Patterns (Serverless Computing London)
PDF
Serverless Architectural Patterns & Best Practices
PDF
Serveless design patterns (VoxxedDays Luxembourg)
PDF
Square Peg Round Hole: Serverless Solutions For Non-Serverless Problems
PDF
Jumpstart your idea with AWS Serverless [Oct 2020]
PDF
Why Serverless?
PDF
Leapfrog into Serverless - a Deloitte-Amtrak Case Study | Serverless Confere...
PDF
Running serverless at scale
PPTX
Serverless at Lifestage
PPTX
How Serverless Changes DevOps
PDF
Common mistakes in serverless adoption
PDF
Docebo: history of a journey from legacy to serverless
PDF
What can you do with lambda in 2020
PDF
Skillenza Build with Serverless Challenge - Advanced Serverless Concepts
PDF
Serverless: Beyond Lambda Functions (V2)
PDF
Introduction to Serverless through Architectural Patterns
Building resilient serverless systems with non serverless components
Square Peg Round Hole: Serverless Solutions For Non-Serverless Problems
Serverless Architectural Patterns
Serverless Design Patterns
Serveless Design Patterns (Serverless Computing London)
Serverless Architectural Patterns & Best Practices
Serveless design patterns (VoxxedDays Luxembourg)
Square Peg Round Hole: Serverless Solutions For Non-Serverless Problems
Jumpstart your idea with AWS Serverless [Oct 2020]
Why Serverless?
Leapfrog into Serverless - a Deloitte-Amtrak Case Study | Serverless Confere...
Running serverless at scale
Serverless at Lifestage
How Serverless Changes DevOps
Common mistakes in serverless adoption
Docebo: history of a journey from legacy to serverless
What can you do with lambda in 2020
Skillenza Build with Serverless Challenge - Advanced Serverless Concepts
Serverless: Beyond Lambda Functions (V2)
Introduction to Serverless through Architectural Patterns
Ad

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation

Building resilient serverless systems with non-serverless components - Cardiff 2020

  • 1. Building Resilient Serverless Systems with Non-Serverless Components Jeremy Daly CTO, AlertMe.news @jeremy_daly
  • 2. Jeremy Daly • CTO at AlertMe.news • Consult with companies building in the cloud • 20+ year veteran of technology startups • Started working with AWS in 2009 and started using Lambda in 2015 • Blogger (jeremydaly.com), OSS contributor, speaker • Publish the Off-by-none serverless newsletter • Host of the Serverless Chats podcast @jeremy_daly
  • 3. Agenda • What is resiliency and what is serverless? • Working with “less-than-scalable” RDBMS • Using unreliable APIs • Managing API quotas • Decoupling our services • Other non-serverless components @jeremy_daly
  • 4. What is resiliency? @jeremy_daly “The ability of a software solution to absorb the impact of a problem in one or more parts of a system, while continuing to provide an acceptable service level to the business.” ~ IBM IT’S NOT ABOUT PREVENTING FAILURE IT’S UNDERSTANDING HOWTO GRACEFULLY DEAL WITH IT
  • 5. What does it mean to be Serverless? • No server management • Flexible scaling • Pay for value • Automated high availability @jeremy_daly Flexible scaling 👈
  • 6. What does it mean to be Serverless? @jeremy_daly ElastiCache RDS EMR Amazon ES Redshift Fargate Anything “on EC2”Lambda Cognito Kinesis S3 DynamoDB SQS SNS API Gateway CloudWatch AppSync IoT Comprehend Serverless Managed Not Serverless DocumentDB (MongoDB) Managed Streaming for Kaca Definitely
  • 7. Everything has limits! • Reserved Concurrency 🚦 • FunctionTimeouts ⏳ • Memory Limits 🧠 • NetworkThroughput 🚰 Some components are better than others @jeremy_daly Know Your Limits
  • 8. Simple ServerlessWeb Service Client API Gateway Lambda DynamoDB @jeremy_daly Highly Scalable Highly Scalable Highly Scalable
  • 9. “I want my, I want my, I want my SQL” ~ Dire Straits
  • 10. Simple ServerlessWeb Service Client API Gateway Lambda @jeremy_daly Highly Scalable Highly Scalable NotThat Scalable 😳 RDS ^ not so RDBMS and FaaS don’t play nicely together: • Concurrency model doesn’t allow connection pooling • Limited number of DB connections available • Recycled containers create zombies
  • 11. Ways to Manage DB Connections • Increase max_connections setting • Limit concurrent executions • Lower your connection timeouts • Limit connections per username • Close connection before function ends @jeremy_daly 🤞 😡 ⚠ 🎲 😱 👎
  • 12. BetterWays to Manage DB Connections • Implement a good caching strategy 💾 • Buffer events for throttling and durability 🏋 • Utilize a proxy service 🛰 • Manage connections ourselves 🤔 @jeremy_daly 👎
  • 13. miss Implement a good caching strategy Client API Gateway RDSLambda Elasticache Key Points: • Create new RDS connections ONLY on misses • Make sureTTLs are set appropriately • Include the ability to invalidate cache @jeremy_daly YOU STILL NEEDTO SIZEYOUR DATABASE CLUSTERS APPROPRIATELY
  • 14. Do you really need immediate feedback? Synchronous Communication Services can be invoked by other services and must wait for a reply. This is considered a blocking request, because the invoking service cannot finish executing until a response is received. Asynchronous Communication 🚀 This is a non-blocking request. A service can invoke (or trigger) another service directly or it can use another type of communication channel to queue information.The service typically only needs to wait for confirmation (ack) that the request was received. @jeremy_daly
  • 15. RDS Buffer events for throttling and durability Client API Gateway SQS Queue SQS (DLQ) Lambda Lambda (throttled) ack “Asynchronous” Request Synchronous Request @jeremy_daly Key Points: • SQS adds durability • Throttled Lambdas reduce downstream pressure • Failed events are stored for further inspection/replay Limit the concurrency to match RDS throughput x Utilize Service Integrations
  • 16. Utilize a Proxy Service • PgBouncer 🏀 • SQL Relay 🏃 @jeremy_daly Client API Gateway Lambda RDSEC2x Fargate 🙀 • Amazon RDS Proxy (Preview) In a “serverless” application? FOR SHAME! 😿
  • 17. Manage connections ourselves 1. Count open connections 2. Close connection if connection ratio threshold exceeded 3. Close sleeping connections with high time values 4. Retry connections with exponential back off @jeremy_daly
  • 19. Count open connections @jeremy_daly Query the processlist to get the total number of active connections
  • 20. Close connection if over ratio threshold @jeremy_daly If we exceed the connection ratio Calculate our timeout Try to kill zombies If no zombies, terminate connection Else, just try to kill zombies
  • 21. Close sleeping connections with high time values @jeremy_daly Query processlist for zombies Kill zombies
  • 22. Retry connections with exponential back off @jeremy_daly If error trying to connect Retry with Jitter
  • 23. Does this really work? @jeremy_daly • Aurora Serverless (2 ACUs) • 90 connections available • 1,024 MB of memory • 500 users/sec for one minute • Avg. response time was 41 ms • ZERO ERRORS
  • 24. We shouldn’t have to do this! @jeremy_daly Amazon Aurora Serverless Aurora Serverless DATA API Doesn’t solve the max_connections issue Slower throughput, not quite ready for synchronous workloads Amazon RDS Proxy Added cost, still doesn’t address scalability issues *PREVIEW* 🥰
  • 26. Manage calls to third-party APIs • Implement a good caching strategy 💾 • Buffer events for throttling and durability 🏋 • Implement circuit breakers 🚦 @jeremy_daly
  • 27. DynamoDB Stripe API The Circuit Breaker Client API Gateway Lambda Key Points: • Cache your cache with warm functions • Use a reasonable failure count • Understand idempotency Status Check CLOSED OPEN Increment Failure Count HALF OPEN “Everything fails all the time.” ~WernerVogels @jeremy_daly 🔥 🔥 🔥 🔥 🔥 Elasticache or
  • 28. What about quotas? • Concurrency has no effect on frequency ⏰ • Stateless functions are not coordinated 😿 • Step Functions StandardWorkflows would be very expensive 💰 • Adding state wouldn’t prevent needless invocations 🗑 @jeremy_daly
  • 29. Can we build a better system? • 100% serverless • Cost effective • Scalable • Resilient • Efficient • Coordinated @jeremy_daly
  • 30. Lambda Orchestrator (concurrency 1) The Lambda Orchestrator DynamoDB LambdaWorker LambdaWorker LambdaWorker Concurrent Executions of the SAME function SQS (DLQ) @jeremy_daly CloudWatch Rule (trigger every minute) SQS QueueSQS (DLQ) Status? Gmail API 250 Quota Units per minute
  • 32. Multicasting with SNS Key Points: • SNS has a “well-defined API” • Decouples downstream processes • Allows multiple subscribers with message filters Client SNS “Asynchronous” Request ack Event Service @jeremy_daly HTTP SMS Lambda SQS Email SQS (DLQ) FUN FACT: SNS to SQS is “guaranteed” (100,010 retries)
  • 33. @jeremy_daly Multicasting with EventBridge Key Points: • Allows multiple subscribers with RULES, PATTERNS and FILTERS • Forward events to other accounts • 24 hours of automated retries Asynchronous “PutEvents” Request ack w/ event id Amazon EventBridge Lambda SQS Client Step Function Event Bus +16 others
  • 34. Key Points: • Filter events to selectively trigger services • Manage throttling/quotas per service • Use Lambda Destinations with asynchronous events Stripe API @jeremy_daly Distribute &Throttle ack SQS Queue Lambda (concurrency 25) Client API Gateway Lambda Order Service "total": [{ "numeric": [ ”>", 0 ]}] RDS SQS Queue Lambda (concurrency 10) SMS Alerting Service Twilio API SQS Queue Lambda (concurrency 5) Billing Service "detail-type": [ "ORDER COMPLETE" ] EventBridge
  • 35. Other non-serverless components • Managed Services • Other cloud services (MongoDB Atlas, ElasticSearch, etc.) • Legacy Systems • Our own serverless APIs 🤔 @jeremy_daly
  • 36. Non-serverless components are inevitable • Know the limits of your components • Use a good caching strategy • Embrace asynchronous processes • Buffer and throttle events to distributed systems • Utilize eventual consistency @jeremy_daly 👈
  • 37. Things I’m working on… Blog: JeremyDaly.com Podcast: ServerlessChats.com Newsletter: Osynone.io DDBToolbox: DynamoDBToolbox.com Lambda API: LambdaAPI.com GitHub: github.com/jeremydaly Twitter: @jeremy_daly @jeremy_daly