How do I implement circuit-breaking patterns using AWS App Mesh?
In this guide, we will implement circuit-breaking patterns using AWS App Mesh with Pulumi. Circuit-breaking is a design pattern used to detect failures and encapsulate the logic of preventing a failure from constantly recurring during maintenance, temporary external system failure, or unexpected system difficulties.
We will create an App Mesh virtual node with outlier detection to implement circuit-breaking. This configuration will prevent cascading failures and ensure that our microservices remain resilient.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an App Mesh
const mesh = new aws.appmesh.Mesh("example-mesh", {
spec: {
egressFilter: {
type: "ALLOW_ALL",
},
},
});
// Create a Virtual Node with circuit-breaking configuration
const virtualNode = new aws.appmesh.VirtualNode("example-virtual-node", {
meshName: mesh.name,
spec: {
listeners: [{
portMapping: {
port: 8080,
protocol: "http",
},
outlierDetection: {
interval: {
unit: "ms",
value: 5000,
},
baseEjectionDuration: {
unit: "ms",
value: 10000,
},
maxEjectionPercent: 50,
maxServerErrors: 5,
},
}],
serviceDiscovery: {
dns: {
hostname: "example-service.local",
},
},
},
});
// Export the Mesh and Virtual Node names
export const meshName = mesh.name;
export const virtualNodeName = virtualNode.name;
Key Points
- App Mesh: AWS App Mesh is used to manage microservices traffic.
- Virtual Node: Represents a logical pointer to a service.
- Circuit-Breaking: Implemented using outlier detection in the virtual node configuration.
Summary
We have implemented circuit-breaking patterns using AWS App Mesh by defining a virtual node with outlier detection. This helps to prevent cascading failures and maintain the resilience of our microservices. The configuration includes specifying the interval, base ejection duration, maximum ejection percentage, and maximum server errors to trigger the circuit breaker.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.