how i built redis rival caching database dustdb?

Muhammad yasirMuhammad yasir
4 min read

I built dustdb and you can see here Dustdb.

I’m Muhammad Yasir a engineer in pakistan and i was nerd since my studies and i got punished by teachers for learning extra thing and when my journey started as a developer i first stuck at database connection and the programming language i was using for the first time was PHP and i thought it is impossible to build something like a database and i became very sad about that i am terrible at coding like a coding muffin.

It was coded in 5 years and researched for month san di struggled days and nights reading different books on internals of database and then i saw something in every database that they were un optimized and not multithreaded.

I started this as my hobby project in golang and C language but after some time i came at point that if i used Assembly rather than C or C++ i can make it unbeatable and it is true that assembly is machine language but it is also true that if you don’t have knowledge about assembler or compiler you will end up writing code which will be slower than compiler or maybe interpreter?

I used LRU and LFU based caching mechanisms in this database and it has web ui and you can set TTL(time to live for caching and purge for it ).

I made docs for it which are available in docs/index.html.

Databases are hardest pill to take not because they are hard but rather than it is hard to build something in a way which whiplashes performance aor something better than existing ones could be hard.

It takes only 22mb of ram which is considered pretty good for old servers and if you see redis it takes 512 mb ram and all other database takes this ior near this much amount of ram except memcached which uses 256+ ram .

I used almost 99.5 efficiency of memory and avoided segmentation at all coast i f you put i bit on disk database like sqlite or postgres or memcache or redis it will take 1 byte /8 bits and 7 bits will be held as useless thing and i solved this problem in Dustdb and it is first database which achieved this thing.

Multithreading is built-in in dustdb.

It supports sam commands like redis and example is given below.

  • setting values(setting key and value in database)
SET name "gujjar"

OK
  • Getting values(getting certain key will show its value)
GET name

"gujjar"
  • Deleting values
DEL key

PING compatibility with redis

PING 

PONG
  • Deceasing value of a key integer
DECR key


value deleted
here is detailed comparison overview of redis,memcached,dragonfly and dustdb. i developed dustdb while studying Operating systems books and databases research papers and made optimized algorithms.
RedisMemcachedDragonflyDBDustDB
TypeIn-memory data storeIn-memory cacheIn-memory data storeIn-memory data store
PerformanceHighHighHigher than bothAbove all three
Data StructuresRich data typesSimple key-valueCompatible with RedisAdvanced key-value data structures
ScalabilityClustering availableLimitedHighly scalableLinear horizontal scaling
LatencyLowLowLower than bothUltra-low latency
Use CasesCaching, messagingCachingCaching, real-time appsCaching, real-time apps
Memory EfficiencyModerate (~70–80%)High (~90%)Superior (~95%)Exceptional (99.5%)
Eviction PolicyLRU, LFULRUCustom algorithmCustom yet OS level optimized algorithms
Minimum RAM Required512 MB+256 MB+512 MB+Only 22 MB — runs like a charm on old mobile servers
Threading ModelMostly single-threadedMulti-threaded but not optimalFully multithreaded, asyncMultithreaded, async-optimized
AlgorithmsEvent loop, RDB/AOFSlab allocator, hash tableCustom scheduler, smart lockingOS-level schedulers, zero-copy pipelines
Garbage HandlingCan leave memory fragmentationCan leak/fragment memoryEfficient GC avoidanceNo garbage buildup — runs clean on legacy servers
LicenseBSD 3-Clause (open source)BSD 3-Clause (open source) (paid hosting)Proprietary (source-available)GNU Public License (100% free)
OwnershipCorporateCorporateCorporateIndividually maintained
PricingFreeFreeFree (limited) / PaidFully free

Conclusion:

Anything is possible if you mess with something it will be solved but if you don’t do this and enjoy life like everyone you will be fade by time.

0
Subscribe to my newsletter

Read articles from Muhammad yasir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Muhammad yasir
Muhammad yasir