Giter Club home page Giter Club logo

consul-postgres's Introduction

Postgres with Consul

Monitoring 2 Postgres databases, using native PG commands.

Screen.Recording.2022-05-01.at.9.46.52.PM.mov

Usage:

# Start docker, force full refresh
docker-compose up --force-recreate --remove-orphans --build

# Tear down
docker-compose down --volumes --remove-orphans
  • Setup uses 2 Postgres databases and one consul server/agent (see docker-compose).
  • Both databases are monitored by consul using a healthcheck.
  • Consul docker image is built with postgres-client so that it can probe Postgres from the server
  • Database is checked every 3s here
    • This script checks pg_isready here
  • If the datbase goes down then it triggers a watch script here
    • This watcher inserts the state change into Consul KV here, but it could really call any endpoint.

Notes

  • There is only a single Consul server running - we should run multiple to ensure HA.
  • There is no Postgres failover - this is merely handling the monitoring of 2 databases as a POC.
  • There could be a liveness probe sent directly from the server, but I like the idea that we could drop this on top of any system (RDS, DO, GCP, etc), and it will "Just work". Since we are using native Postgres, it works with an Postgres-compatible docker image - no extensions required.
  • I've written everything on the consul side in shell scripts for now. Could be moved to Rust/Go/Python/etc for better DX.

Ideas

Could we use a local DB for service discovery - store availabilty data which is replicated p2p to every other service?

Should we just store all the availability state in a shared Postgres?

  • Gets rid of KV store
  • Consolidates on a single tool
  • Atomic - no threat of split brain

Can we wrap all of this into a single Elixir cluster?

  • Genserver for "pings" - healthcheck
  • Genserver for "pooling" - hold open some connections like pgbouncer
  • Reverse proxy for loadbalancing/message queing
  • Globally distributed - multitenant

consul-postgres's People

Contributors

kiwicopple avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

consul-postgres's Issues

assets

Demo video

Screen.Recording.2022-05-01.at.9.46.52.PM.mov

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.