Nick Fisher's tech blog

Java

Configuring, Testing, and Using Circuit Breakers on Rest API calls with Resilience4j

The source code for what follows can be found on Github.

The circuit breaker pattern, popularized by Netflix [using Hystrix], exists for a couple of reasons, the most prominent being that it reduces load on a downstream service when it is not responding properly [presumably because it’s under duress]. By wrapping operations that might fail and get overloaded in a circuit breaker, we can prematurely prevent cascading failure and stop overloading those services.

How to Retry API Requests in Java using Resilience4j

The source code for what follows can be found on Github.

When you’re working with distributed systems, it is often the case that some clones of a service running can be slow to respond, while still others are functioning perfectly normally. Therefore, when you just hit a load balancer and the load balancer chooses a backend, it can sometimes be beneficial to retry the request. Other things like periodic and small database stalls or random GC stop-the-worlds are examples where retries can smooth the experience for the client of your service.

An Introduction to Redis Streams via Lettuce

The source code for this article can be found on Github.

Redis streams are an interesting data structure that act as a sort of go-between for list and pub/sub operations: It’s like a list in the sense that anything pushed onto the stream is retained, it’s like pub/sub in the sense that multiple consumers can see what is happening to it. There are many other features of streams that are covered in that article, but that’s at least how you can think of it at the start.

Redis Transactions, Reactive Lettuce: Buyer Beware

The source code for what follows can be found on Github.

Redis Transactions do not operate exactly the way you would expect if you’re coming from a relational database management system like MySQL or postrgres. It’s mostly useful for optimistic locking, but honestly there are better ways to accomplish many of the things you’re probably trying to, like running a lua script with arguments [which is guaranteed to be atomic]. The documentation on transactions in redis describes some of the caveats, the biggest one probably being that it does not support rollbacks, only commits or discards.

Subscribing to Redis Channels with Java, Spring Boot, and Lettuce

The source code for what follows can be found on Github.

Pub/Sub in redis allows a publisher to send things to subscribers without knowing who is actually subscribed. In a previous post, we covered a simple unit test for publishing and subscribing to lettuce, but if you want to have a subscription initialized on application startup, and respond to events, we’ll have to do a bit more, which I’ll demonstrate here.