Sign in

In a distributed system, leader election can be critical to coordinate work. In this post, I will quickly show how you can use etcd, a consistent key-value store which uses RAFT protocol for consensus and is used by famous projects like Kubernetes etc, to add leader election to your distributed application.

First, we need a c++ etcd v3 client. We will use GitHub — etcd-cpp-apiv3/etcd-cpp-apiv3 (follow the instructions on the ReadMe to build).


We will use the add and watch api provided by etcd.

Step 1: Each app instance takes lease with a keep alive time and using the lease…

Aim of the article:

  1. Deploy API gateway in front of a micro-service (say foo)
  2. Delegate authN to another micro-service (say auth) for all requests
  3. Enable OAuth 2.0 Google authN in the micro-service auth
  4. Forward user info to other micro-services upon successful authN


  1. authlib: I have developed my example on the one provided here
  2. traefik documentation for forwardAuth plugin:

I recently started learning about how authN and authZ is solved in micro service architecture. Unlike monolith applications where session information is stored and available to be consumed across all APIs, in micro service architecture it is not…


I write about tech

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store