2 minute read

In Part 1, I introduced the idea behind the cloud-circuitbreaker — a distributed, annotation-driven circuit breaker backed by DynamoDB.
In Part 2, we walked through how failure detection, TTLs, and state tracking work.

Now let’s talk real usage: how does this plug into your actual codebase?


🧩 Spring Boot Autoconfiguration

The library supports Spring Boot using simple annotation-based wiring — no extra configuration needed.

@CloudCircuitBreaker(
    function = "getRates",
    fallback = "getRatesFromCache"
)
public Rate getRates(String currency) {
    return externalRateService.fetchLive(currency);
}

public Rate getRatesFromCache(String currency) {
    return cacheService.getLastKnownRate(currency);
}

Spring picks this up using autoconfiguration — under the hood, it’s just a Spring @BeanPostProcessor that wraps annotated beans with a proxy.


⚙️ Configuration via Properties

You can configure behavior using application properties:

cloudcb.serviceName = order-service
cloudcb.tableName = circuit-breaker-states
cloudcb.tableType = dynamodb
cloudcb.region = us-east-1
cloudcb.failureThreshold = 2
cloudcb.resetTimeoutSeconds = 240

This makes tuning super simple for different environments.


☁️ AWS Lambda Compatibility

For AWS Lambda users — you’re covered.

When using the library inside Lambda handlers, simply annotate your logic methods the same way.
The proxy layer is compatible with plain Java objects and doesn’t rely on servlet containers or web context.

@CloudCircuitBreaker(function = "userProfileHandler", fallback = "fallbackHandler")
public UserProfile handleRequest(Input input) {
    return userService.fetchUser(input.id());
}

public UserProfile fallbackHandler(Input input) {
    return userService.fetchFromCache(input.id());
}

Make sure you include the dynamodb client dependency in your pom.xml or use the prebuilt module.


🏗️ Maven Integration

If you’re building a larger system, include the library like so:

<dependency>
  <groupId>io.clinton</groupId>
  <artifactId>cloud-circuitbreaker-parent</artifactId>
  <version>1.0.0</version>
</dependency>

Works in both Spring Boot and plain Java apps.


🌐 Module Structure

The project is structured as:

  • core: the annotation processor, breaker logic, and shared interfaces
  • spring: Spring-specific wiring
  • lambda: AWS Lambda runtime integration (Java 17+ ready)
  • examples: Sample apps using both styles

Future versions may include Micronaut and Quarkus support.


🧠 When to Use This

You’ll benefit from this library if:

  • You’re on AWS and want to avoid Redis or coordination services
  • You deploy multiple instances (Lambda, ECS, etc.) and need shared circuit state
  • You want annotation-based ergonomics like Spring’s @Retryable but distributed

🧪 Try the Examples

Clone and run the examples inside /example to get a feel of how the library fits in.


📣 What’s Next

In Part 4, I’ll walk through:

  • How to write your own circuit state backend (e.g., Redis)
  • Metrics and observability via CloudWatch or Prometheus
  • Handling partial failures or retries cleanly

Have feedback or an idea to improve this?
Open an issue or ping me on LinkedIn.

Until next time — build resilient! 🚀