Code Monkey home page Code Monkey logo

fault-tolerant-gateway's Introduction

Fault-Tolerant Gateway

This project introduces a fault-tolerant gateway that functions as both a circuit breaker and a load balancer. It employs the resilient-scalable-cache as a key-value database.

Watch the demo

Watch the demo

The gateway is developed using the Elixir programming language, which inherently provides fault tolerance. Elixir allows developers to create applications that can automatically restart upon encountering errors, without losing their state and continuing to operate as if nothing happened. This resilience is due to Elixir's actor-based architecture.

The gateway maintains a Service Registry, which contains registered microservices responsible for executing business logic. Each microservice is required to register itself in the Gateway's Service Registry by calling the POST /register endpoint.

The Service Registry consists of keys stored in the resilient-scalable-cache, an alternative to Redis. The key name corresponds to the microservice name, and the values associated with the key are an array of references to the microservice replicas that the Gateway can use for redirecting requests.

For instance, consider a microservice named client-service. When a replica of this service starts, it sends a POST /register request to the Gateway, with the request body containing { "service": "client-service", "address": "the url to the replica" }. The Gateway then registers this microservice replica in the Service Registry by storing an array under the client-service key:

client-service: [{url to the replica, port, ...}]

The Gateway performs load balancing on replicas of the same microservice using the Service Registry. For example, when a call is made to the client-service through the Gateway, it employs the round-robin technique on the replicas stored under the client-service key.

Additionally, the Gateway serves as a circuit breaker. When forwarding a request to a microservice replica, if the Gateway detects a failed request, it records the failure in the cache. In the case of the client-service, when the Gateway detects a failed response from a replica, it creates a key called circuit-breaker#{the url to the replica} and sets its value to 1, indicating that one failure has occurred so far. After logging the failure, the Gateway proceeds to try the next replica until it finds a functional one. If a replica surpasses a predetermined failure threshold, it will be removed from the Service Registry.

fault-tolerant-gateway's People

Contributors

iondodon avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.