Infuse

Welcome to Infuse’s Documentation. Infuse is an extension for Insanic that implements the circuit breaker pattern to Insanic’s inter-service requests. Basically, it wraps Insanic’s Service object’s dispatch method so that it fails before the request is made if the target is deemed unhealthy. Global state of each service is stored in redis.

Background

This project’s inception was when I was working for my former employer during the research phase of migrating a monolithic application to micro services. Having a device that would prevent failure of a system and or systems by a build up of backpressure is especially needed in a distributed system. Unable to handle this properly will cascade downstream and in the worst case, ultimately, would crash the whole system.

So it was decided that we would need a strategy to manage the situation if it ever arose. Other technologies were researched, but back when the migration was happening, micro service technologies were still in their infancy. Envoy was still in beta, App Mesh didn’t exist, Netflix’s Hystrix is in Java (our whole system was planned to be in Python). Therefore we had to either use a python library or implement our own. Long research into available python libraries eventually landed me upon pybreaker. The implementation looked simple enough but with one big caveat, it wasn’t async.

We were using Insanic, an in-house developed Python framework based upon Sanic, which was developed with asyncio. So for our framework to work properly without blocking the running loop, when communicating with a redis backend, we need to use a customized implementation, thus commenced the development of Infuse.

The name may not be straight forward at first, but at the company we had an unspoken convention where all packages would start with “in~”. So basically, since this is a circuit breaker, and a the circuit breaking usually happens in a “fuse” box, so consequently this packages’ name came out to “infuse”. But to avoid name conflicts in pypi, the package name is insanic-infuse, but actually imports are infuse.

Features

  • asyncio implementation of pybreaker’s circuit breaker

  • Asynchronous redis storage using aioredis

  • patching of Insanic’s Service object

  • Initialization of state on Insanic server start.

Going Forward

I am unsure if Infuse is needed in the future, or if circuit breaking implementation should be handled in the application. There are many other great implementations and other technologies that handle circuit breaking for you, for example, Envoy and AWS’s utilization of Envoy for their App Mesh.

So, this extension will probably be deprecated it favor of better technologies. Unless major bugs are found, further development may not be needed.

API Reference

If you are looking for information on a specific function, class or method, this part of the documentation is for you.

Indices and tables