loading...
Cover image for Writing a Cache Server

Writing a Cache Server

thetinygoat profile image Sachin Saini ・2 min read

Introduction

For the past few months, I have been working on a cache server similar to Redis. It currently has the following 4 data structures:
1) Hashes - These are hashmaps which consist of multiple related fields.
2) Sets - These are regular sets, you can add, remove members in a set or check membership
3) Keys - This is simple key-value pairs with an expiration time attached to them
4) Lists - These are doubly linked lists, they can be used to create message queues or other things

Motivation

My main motivation was to learn but as the project grew, I got more interested in making it a serious open source project, so I am working towards it now. I am aiming for small to medium size apps for which Redis can be overkill or not viable due to certain reasons.

Components of a cache server

Alt Text
Several pieces come together to build a cache server, a Communication protocol that both a client and the server follows for communication, a request parser that parses the incoming requests, validates them and spits out processed queries that the data structure handlers can understand, a memory manager to keep track of memory allocated to cache objects so your cache does not take up the whole system, core data structure APIs. This is just a high-level overview of some parts of the server, there are many more, and when you get to the implementation part these things are complex in themselves.

Introducing DictX

So the server is called DictX(yes, this is the best I could do). Right now it doesn't do anything, I am still writing a request parser and working on the communication protocol. I have already finished the data structure APIs, they will most probably stay the same.
This server is written in Go, now I could have chosen something like Rust, but I think for now Go does the job pretty well and easy concurrency is a major advantage.

Say Hi!

I will be writing more articles on the internals of the server in the future, If you would like to contribute or talk to me feel free to reach out to me on Twitter.
Here's the link to the DictX repo: https://github.com/thetinygoat/DictX
If you like the project, I would really appreciate it if you would star the repo.
Follow me on Twitter and Github.

Posted on by:

thetinygoat profile

Sachin Saini

@thetinygoat

Currently a student, love to post about all things tech.

Discussion

markdown guide