General Architecture

DB

Before We start

It’s totally theoritical I have no practical experience in this topic. I want that(practical experience) that’s why I am writing this blog 😉 . This is an original content.

Let’s start

Problem Statement ->

This is a distributed system. Multiple system is trying to read or write from a file, Now how to make it safe ? . Safe in the sense that how can sys 4 possibly know that sys 1 is writing in the file. or how can sys 2 and sys 3 can know that it can get stale data.

Solution 1

As this is a totally controlled environment, we can write our code for write() in the file as, when any of the system loads file in it’s own ram to edit or insert it creates a new file as filename.safe with edit permission to only that system. We can add multiple metadata in filename.safe. Then after completion of task by that system it will remove filename.safe. Now if the sytem 4 wants to write in filename then it will check first that if filename.safe exists or not, if not then it will write by creating .safe else it will wait till .safe is deleted. For reading you can write your read() fucntion as to return request with different code for stale request.

Solution 2

We can write a file controller which will run on system 5 and it will record write request from different system with timestamp and execute it sequentially if some request take lot of time(that’s why timestamp). I think this will be a better solution as it is non blocking in nature and server need not worry as there is only one agent writing to it. I think it is also consume less resource as no one has to continuously check it .safe file exist or not.

That’s all folks.