Command Palette

Search for a command to run...

Назад к скиллам
скилл № 09176

core-algorithms-system-design

Use when the user asks about consistent hashing, hash rings and virtual nodes, rendezvous or jump hash, Bloom filter false positive rate, Count-Min Sketch…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить core-algorithms-system-design в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Core Algorithms for System Design

Purpose

A handful of algorithms keep appearing inside caches, databases and stream processors: ways to spread keys over changing node sets, and compact sketches that answer membership, frequency and cardinality questions approximately. This skill gives each algorithm's guarantees, sizing formulas and a decision table.

Agent Protocol

Trigger

"consistent hashing", "hash ring", "virtual nodes", "rendezvous hashing", "jump hash", "bloom filter", "count-min sketch", "HyperLogLog", "top-k", "merkle tree", "geohash".

Input Context

  • Problem: key placement, membership test, frequency, distinct count, data reconciliation, proximity search
  • Scale (items, nodes), acceptable error, memory budget, update/delete needs

Output Artifact

Algorithm choice with sizing math and a reference implementation. No file unless requested.

Response Format

Problem: {what is asked}
Algorithm: {choice} because {property}
Sizing: {parameters and formula result}
Error/guarantee: {bound}
Code: {snippet}

1. Distributing Keys over Nodes

hash(key) % N remaps about (N-1)/N of keys when N changes — unusable for caches and storage that scale.

Scheme Keys moved when a node is added Lookup Notes
Consistent hashing (ring) ~K/N (only the new node's arcs) O(log(N·v)) binary search needs virtual nodes for balance; supports weights via vnode counts
Rendezvous (HRW) hashing ~K/N O(N) per key (score every node) no ring state; easy weights; good for small N
Jump consistent hash (Lamping & Veach) ~K/N O(log N), no memory nodes must be numbered 0..N-1; only add/remove at the end
Maglev hashing small, bounded disruption O(1) table lookup used in L4 load balancers

Ring with virtual nodes:

import bisect, hashlib

def h(s: str) -> int:
    return int.from_bytes(hashlib.blake2b(s.encode(), digest_size=8).digest(), "big")

class HashRing:
    def __init__(self, vnodes: int = 160):
        self.vnodes, self.points, self.owner = vnodes, [], {}

    def add(self, node: str) -> None:
        for i in range(self.vnodes):
            p = h(f"{node}#{i}")
            bisect.insort(self.points, p)
            self.owner[p] = node

    def remove(self, node: str) -> None:
        for i in range(self.vnodes):
            p = h(f"{node}#{i}")
            self.points.remove(p)
            del self.owner[p]

    def get(self, key: str) -> str:
        if not self.points:
            raise LookupError("ring is empty")
        i = bisect.bisect(self.points, h(key)) % len(self.points)   # first point clockwise
        return self.owner[self.points[i]]
  • Without vnodes, one node's share of the ring varies widely (the largest arc is about ln N / N of the ring); with v vnodes per node the relative imbalance shrinks roughly like 1/√v — 100–200 vnodes per node is typical.
  • Replication: walk clockwise to the next R distinct physical nodes (Dynamo/Cassandra style).
  • Bounded-load variants cap any node at (1+ε)× average load for hot-key resilience.

2. Bloom Filter (membership, no false negatives)

  • m bits, k hash functions, n inserted items. False-positive probability p ≈ (1 − e^(−kn/m))^k.
  • Optimal k = (m/n)·ln 2; required bits m = −n·ln p / (ln 2)² ≈ 9.6 bits per item for 1%, 14.4 for 0.1%.
  • Example: 10 million keys at 1% → m ≈ 95.9 Mbit ≈ 12 MB, k ≈ 7.
  • Use: skip disk reads for absent keys (LSM-tree SSTables in RocksDB/Cassandra), CDN/cache admission, crawler "seen URL" sets.
  • Cannot delete: use a counting Bloom filter (counters instead of bits) or a cuckoo filter (supports deletes, better space at low p).
  • Implementation tip: derive k indexes from two hashes (Kirsch–Mitzenmacher: g_i = h1 + i·h2 mod m).

3. Count-Min Sketch (frequency)

  • d rows × w counters; each item increments one counter per row; estimate = min over rows. Never underestimates; overestimates by at most ε·N with probability 1−δ when w = ⌈e/ε⌉, d = ⌈ln(1/δ)⌉.
  • Use for heavy hitters / top-k (pair with a min-heap), rate of events per key in streams.

4. HyperLogLog (distinct count)

  • m = 2^b registers storing the max leading-zero run of hashed items; standard error ≈ 1.04/√m. With m = 16384 (b = 14), ~0.81% error in ~12 KB (Redis PFADD/PFCOUNT uses this configuration).
  • Mergeable: union of HLLs = register-wise max — great for daily/hourly unique users rolled up.

5. Merkle Trees (reconciliation)

Hash leaves (data blocks/key ranges), hash pairs upward to a root. Two replicas compare roots and descend only into differing subtrees — anti-entropy in Dynamo-style stores (Cassandra repair), Git, and certificate transparency logs. Cost: O(log n) hashes to locate each difference.

6. Geospatial Indexing

  • Geohash: interleave latitude/longitude bits into a base-32 string; shared prefix ≈ nearby (but neighbours across cell edges have different prefixes — always query the 8 neighbouring cells).
  • Al
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл core-algorithms-system-design?

Use when the user asks about consistent hashing, hash rings and virtual nodes, rendezvous or jump hash, Bloom filter false positive rate, Count-Min Sketch, HyperLogLog, top-k, Merkle trees or geohash. Produces sizing formulas, code and when to use each. Not for rate limiting (use rate-limiting) or shard topology (use architecture-database-scaling).

Как установить скилл core-algorithms-system-design?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл core-algorithms-system-design запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить core-algorithms-system-design с