Member-only story

Distributed System Lock Implementation using Redis and JAVA

The purpose of a lock is to ensure that among several application nodes that might try to do the same piece of work, only one actually does it (at least only one at a time).

Md Sajedul Karim
5 min readMar 20, 2021
Photo by Emile Perron on Unsplash

In current days I worked on Redis lock-in distributed system. In distributed system Locking/concurrency management is a very important thing. Without prior knowledge, many unwanted problems may occur.

What we will learn here

  1. Create a simple wallet backend with buggy architecture and code
  2. Create the Race condition and identify the problem
  3. Solve the problem using new architecture and implementation
  4. Share the codebase with file descriptions

Here I am sharing an application architecture. Suppose this is a bank wallet application backend. Its architecture is very simple. It has a single app server, single app node, single Redis server, and a single database

Application general architecture

Here, Clients request directly to come to the application server (Tomcat), which passes to the application. Here we don't have a load balancer and our application has a single instance. This application has a single Redis server and a single database.

Prerequisites
For this tutorial, you must have knowledge of spring boot’s basic architecture. To achieve this you can follow my bellow tutorial

In a traditional wallet system, for fund transfer feature requires one sender, one receiver, and transaction amount. For example, the client’s request is :

--

--

Md Sajedul Karim
Md Sajedul Karim

Written by Md Sajedul Karim

Back-end developer, Spring, JAVA, Distributed system, AWS, Google Cloud, Docker, CD/CI, Kubernetes, databases. https://www.linkedin.com/in/sajedulkarim/

Responses (1)

Write a response