DEV Community

Cover image for Deploy "The EventBridge Circuit Breaker" pattern today (AWS API Gateway, Lambda, EventBridge, DynamoDB)
Matt Coulter
Matt Coulter

Posted on • Updated on

Deploy "The EventBridge Circuit Breaker" pattern today (AWS API Gateway, Lambda, EventBridge, DynamoDB)

Alt Text

This is a pattern adapted from "The Circuit Breaker" by Jeremy Daly. I used EventBridge to route service call failures to a lambda that inserts them into DynamoDB with a 60 second Lifespan. Then when consumers call the API Gateway to call our external service we check if the number of errors in the last 60 seconds is above our threshold. If it is, we instantly error saving lambda execution costs and user time.

The pattern is here:
https://github.com/cdk-patterns/serverless/blob/master/the-eventbridge-circuit-breaker/README.md

This pattern is available in Python/TypeScript AWS CDK versions but also each version has the native CloudFormation checked in as template.yaml.

Top comments (3)

Collapse
 
byrro profile image
Renato Byrro

Interesting idea. I've seen implementations using only Lambda + Dynamo and others using Step Functions. EventBridge is also interesting. I'm thinking Kineses might also fit.

Just a heads up, the pattern was suggested by Martin Fowler long before. AWS also refers to him. I don't know if anyone else before him did, though. 😉

Collapse
 
nideveloper profile image
Matt Coulter

Thanks for the heads up. I can absolutely add him in with links to his content. That’s why I am trying to pull this all into one central place so these things don’t get lost!

Collapse
 
nideveloper profile image
Matt Coulter

Updated with link to Martin Fowler and his article from 2014 on the circuit breaker pattern.