Shard Rebalancing in KV Store

(OpenAI)
In a distributed key-value store, data is partitioned across multiple shards, each responsible for a contiguous range of keys. Over time, shard boundaries may become suboptimal
due to overlaps or gaps, leading to inefficiencies in storage and access. This document presents a systematic approach to rebalancing shards under strict constraints.

######## Problem Definition ########
Each shard is defined as:

class Shard:
def __init__(self, id: str, start: int, end: int):
self.id = id
self.start = start
self.end = end

def __repr__(self):
return f"{self.id}:{self.start}:{self.end}"

A shard covers all keys in the inclusive range `[start, end]`.

Given:
- A list of shards
- A coverage limit `limit` (maximum number of shards that can cover any single key)
...




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.