Back to Projects

Distributed Sharding Manager

SHARDING.JS

Status

Active / NPM Package

Year

2024

High-performance, cross-machine sharding manager for Discord bots. Enabling seamless communication between multiple shards across different machines using Redis.

As Discord bots scale, the single-machine vertical scaling limit is inevitably hit. Sharding.js provides a horizontal scaling solution. It abstracts the complexity of cross-process communication using a Redis pub/sub layer, allowing shards to communicate as if they were in the same process.

System Architecture

Designed as a message-bus agnostic layer, the default Redis adapter uses a high-throughput pub/sub mechanism. Each machine runs a ShardManager instance that coordinates via a global state stored in Redis, allowing for dynamic shard allocation and failover.

Cross-Machine

Supports multiple servers/IPs via message bus agnostic publish/subscribe layer.

Hot Reload

Helpers for swapping shards without dropping sessions or sessions loss.

Event Replay

Failed event replay with observable buffers for operator control.

Technical Challenges

Network Partitioning

Developed a heartbeat mechanism to detect zombie shards and trigger automatic redistribution during network failures.

Serialization Overhead

Optimized the message bus to use binary serialization for high-frequency internal events.

Core Stack

TypeScriptRedisDistributed SystemsDiscord.jsNode.jsNPMESBuild

Source Access

GitHub Protocol

Developer Note

This project represents a push towards localized, high-performance infrastructure. Every architectural decision was made to prioritize data ownership and system resilience.