Increment Failure Count
API Gateway
Lambda Function
Twilio API
A client application makes a request to an API Gateway endpoint. This forwards the request to a Lambda function.
The Lambda Function checks the value of a global variable to determine the current status of the "circuit". If the status doesn't exist, a request is sent to DynamoDB to rehydrate the state.
If there have been no recent failures, the circuit is in the "closed" state and the call can be made to the Twilio API.
If the call succeeds, the response is returned to the Lambda function and then sent back to the client via the API Gateway.
If the API call fails, we increment the failure count of our global variable, update our DynamoDB cache, and respond to our client with an error.
Once the failure count has reached a certain threshold, the circuit status should be marked "open", which means we immediately return an error to the client on subsequent requests.
Periodically, we want to try a "half open" request to see if the API is working again. If it fails, we just return the error to the client.
If our "half open" request succeeds, we update our cache and mark the status "closed". We then return the results to the client.
The client can be a web browser, an application, or even another service in AWS.
Amazon API Gateway is a service that lets you route API requests. The API Gateway is mapped to a Lambda function to process the request.
The Lambda Function handles the remote API calls as well as performs the circuit breaker logic.
The "Status" represents the current state of the circuit. It can either be "closed", "open", or "half open".
A third party API or other downstream component. It's possible for this component to become unavailable or to exceed our quota.
DynamoDB table used to store failure counts/status across multiple Lambda functions.