The WAL (Write-Ahead Log) technology has been used in many systems.
The mechanism of a WAL is that when a client writes data, the system does two things:
- Write a log to disk and return to the client
- Write the data to disk, cache or memory asynchronously
There are two benefits:
- If some exception occurs (i.e. power loss) we can recover the data from the log.
- The performance is good because we write data asynchronously and can batch operations
Why not just write the data into disk directly? You make every write directly to disk. On success, you tell client success, if the write failed you return a failed response or timeout.
In this way, you still have those two benefits.
- You do not need to recover anything in case of power off. Because every success response returned to client means data really on disk.
- Performance should be the same. Although we touch disk frequently, but WAL is the same too (Every success write for WAL means it is success on disk)
So what is the advantage of using a WAL?