Circuit Breakers: Stock Markets and Distributed Systems

Reading Time: 4 minutes

There are many parallels between the stock markets and the distributed systems in computer science. This post, in particular, is about circuit breakers prevalent in them for better resilience against irrational exuberance and upstream service errors respectively. In particular, this is about exploring breakers in stock markets from a distributed systems perspective. 

Of late, the US stock market (and the non-US ones too) has been quite volatile, to say the least. CBOE VIX index  (also known as the ‘fear index’) which measures implied volatility in the S&P 500 index, has traversed a wide range between highs and lows, fluctuating several points on many of the days in March and April, peaking at 82.69 on 16th March (stock market bottomed out on 23 March, both as of May 10, 2020).  

In recent times, similar levels of volatility were last observed during the Global Financial Crisis (GFC) of 2008. Markets are driven by emotions and speculation as much they are driven by algorithms and numbers.

During periods of high volatility, a “thundering herd” of panic sell-off can be potentially triggered. To put a stop to this herd, a circuit breaker or a trading curb kicks in. Many would have experienced electrical circuit breakers in daily life when dealing with not-so-pleasant electrical issues wherein an overload would have triggered the breaker, requiring a manual reset. Similarly, these circuit breakers are triggered corresponding to a fall of 7%, 13%, and 20% in levels of the S&P 500 index, and markets are halted for 15 minutes each for the first two and the entirety of the trading day for a 20% drop. The goal of each of these curbs is to prevent the need for the next one. World Economic Forum and Reuters have crisp short reads on the recent circuit breaker events. 

In March alone, these circuit breakers were triggered four times. This is very significant since, before these clustered breaker events, the circuit breakers were triggered only once in 1997 after being instituted to avoid a repeat of the 1987 Black Monday crash.

On one of these days in March, with these breakers triggered, other than dread at the roller coaster-like volatility, this reminded me of circuit breakers in distributed systems. In these systems, these breakers are a design pattern (popularized by Michael Nygard in the book Release It!) used often by services/clients when their dependent service is unavailable. It works by isolating the unavailable/erroring service from calling clients and periodically monitoring the service before allowing some (half-open) or all the traffic (open) states.  The overarching goal here is to avoid escalation of an error state to a crash and cascading failures in general.

Following diagram from Azure Circuit Breaker pattern – Cloud Design Patterns illustrates the state transitions better: 

Circuit Breaker states

Cascading failures are those wherein a failure in one service avalanches into larger problems in multiple dependent services. One hapless git commit somewhere deep in the stack ends up breaking your photo-sharing service. It would be hard to miss this class of failures from postmortems of popular website/service incidents. This clip from Ice Age sort of exemplifies a cascading failure in my mind:

Getting back to the stock crash, the parallels here are clear. The “error”, in this case, is a precipitous fall in the Index exacerbated by real-life unexpected out-of-the-blue conditions (stock markets hate uncertainty more than an actual downturn on a slow burner). The “clients” here are the traders who, in response to this panic, try to de-risk their portfolio by liquidating it. This further stokes panic creating a self-perpetuating rapidly escalating feedback loop, causing more “errors”. Rightfully, the circuit breakers kick in and create a time gap (much like the insulating gap in electrical breakers) between traders and the market, so that short-term gut reaction is (hopefully) supplanted by more non-short-term calculated approaches. Should these breakers fail to kick in, the cascading failures, in this case, would be the potentially catastrophic damage to the market cap of listed companies and even the economy in the worst case, if left unabated. This whole flow gets complex when “clients” (can be automated/misconfigured algos) and “errors” (flash crashes) are not as straightforward.

In 1987, when these circuit breakers were not in place, Dow Jones (DJIA) fell by about 22% in a single day and billions were wiped out of many funds (including some of the crème de la crème like Fidelity Magellan managed by Peter Lynch). Such market crashes, in general, are not healthy since recovery is not symmetrical, in other words, it is much harder to gain than lose.  So much so that there is a well-worn adage which goes like:

“The market takes the stairs up and the elevator down” 

Photo Credits:

  1. https://en.wikipedia.org/wiki/File:Circuit_Breaker_115_kV.jpg
  2. Google Search Stock Summaries for the VIX index.
  3. https://docs.microsoft.com/en-us/azure/architecture/patterns/circuit-breaker