Skip to main content
Harmanpreet Singh
All work

Coursework: Distributed systems

Distributed key-value naming service

A Java hash-ring naming service: a bootstrap server and name servers that look up, insert and delete keys, and rebalance key ranges as servers join and leave.

What it is

A naming service stores key and value pairs across several machines and has to answer "which machine holds this key?" quickly, even while machines come and go.

I implemented a small version in Java. Keys live on a ring of 1024 positions, each name server owns a range of that ring, and when a server joins or leaves, only the affected range moves.

My part

I wrote the bootstrap server and the name server for the course, individually.

Course project for Distributed Computing Systems. It demonstrates the mechanics of consistent hashing, not a production system.

Stack

  • Java
  • TCP sockets
  • Consistent hashing
  • Command-line client

What is inside

Three roles communicate over sockets: a bootstrap server, name servers and a user command interface.

  1. 01

    Bootstrap server

    Acts as the node with id 0, loads the initial key-value pairs from a config file, keeps the map of ring members, and receives lookup, insert and delete commands, forwarding each to the owner.

  2. 02

    Name servers

    Each name server owns a range of the key space 0 to 1023, joins and leaves dynamically, and tracks its predecessor and successor on the ring.

  3. 03

    Join and leave

    When membership changes, the affected key range is reassigned and the keys in it are transferred to the new owner, so the rest of the ring is untouched.

  4. 04

    Storage

    Pairs live in memory and are seeded from the config file. Nothing is persisted, and this page does not claim recovery after a crash.

901-100101-380381-640641-900ABCDkey space0-1023
Four servers share the key space
901-100101-380381-510511-640641-900ABECDkey space0-1023
Server E joins: only one neighbour's range is split
Illustration of consistent hashing. Node positions and ranges are examples, not output from my implementation.