Skip to content

narvikd/nubedb

Repository files navigation

NubeDB

NubeDB is a simple distributed key-value database that uses the Raft consensus algorithm for data replication and consistency.

Features

  • Distributed and replicated data storage
  • Simple to use
  • Automatic fail-over and recovery if any of the nodes go down.
    • Limitations:
      • The system needs 1 leader and 2 nodes to operate correctly.
      • Instability happens when the cluster goes as far as 1 leader and 1 node, this situation should always be avoided.
  • TODO:
    • True auto-scaling, in which a number of arbitrary nodes can be removed when the whole cluster is down, and the system can still reach a quorum on startup.

Table of Contents

Getting started

Starting a cluster

You can edit the docker-compose.yml to enable performance mode at the cost of having larger DB files.

This is done by uncommenting :

environment:
  - FSM_PERFORMANCE=true

To start the cluster:

docker-compose up -d

Using the API

NubeDB provides a simple REST API for accessing its k/v database. You can interact with it using any HTTP client.

Consensus

State

To check the consensus state, you can send a GET request to consensus:

Healthcheck

To check the consensus health, you can send a GET request to health. It will return only a status code for simplicity:

Database

Store

To store a value for a key, you can send a POST request to store:

Get

To retrieve a value for a key, you can send a GET request to store:

GetKeys

To retrieve all keys in the DB, you can send a GET request to store/keys:

Delete

To delete a key, you can send a DELETE request to store:

Backup

To get a full backup of the DB, you can visit or send a GET request to store/backup:

Restore

To restore a backup of the DB, you can send a POST request to store/restore:

First ensure you are sending a form-data with a key backup as a file:

Example: