How praneeth-nyc/distributed_database_system works
This repository implements a small distributed employee database: clients submit employee operations to a FastAPI node, leaders append changes to a Raft log, and applied entries update the employee table. Nodes also expose Raft state and protocol endpoints, coordinate elections and replication over HTTP, and persist Raft state, logs, and snapshots in MySQL. The graph follows shown calls and documented module references; snapshot internals and some runtime wiring are not excerpted, so uncertain links are omitted.
Main entry points: dependencies.py Service wiring · raft_services.py Raft state machine · main.py FastAPI app · database.py Database adapter
Components 18
API and models
- FastAPI app
node/main.py - Employee routes
node/routes/employee.py - Raft routes
node/routes/raft.py - Health route
node/routes/health.py - API and log models
node/models.py - Employee operations
services/employee_services.py
Raft coordination
- Raft state machine
services/raft_services.py - Peer transport
services/cluster_services.py - Log application
services/replication_services.py - Snapshot management
services/snapshot_services.py
Persistence and data
- Raft persistence
services/persistence_services.py - Database adapter
database/database.py
Node setup
- Service wiring
services/dependencies.py - Node configuration
config/config.py - Process entry
run.py
Other components
- API client
- MySQL
- Peer nodes
Connections 29
- Process entry → Node configuration: loads configuration
run.py - Process entry → FastAPI app: creates app
run.py - FastAPI app → Service wiring: initializes services
node/main.py - FastAPI app → Health route: registers route
node/main.py - FastAPI app → Employee routes: registers route
node/main.py - FastAPI app → Raft routes: registers route
node/main.py - API client → Employee routes: requests
node/routes/employee.py - API client → Raft routes: requests
node/routes/raft.py - API client → Health route: checks health
node/routes/health.py - Employee routes → Employee operations: dispatches
node/routes/employee.py - Employee routes → API and log models: validates payloads
node/routes/employee.py - Raft routes → Raft state machine: dispatches
node/routes/raft.py - Raft routes → API and log models: validates payloads
node/routes/raft.py - Employee operations → Raft state machine: appends operations
services/employee_services.py - Employee operations → Database adapter: reads employee data
services/employee_services.py - Raft state machine → Raft persistence: loads and saves state
services/raft_services.py - Raft state machine → Peer transport: dispatches replication
services/raft_services.py - Raft state machine → Log application: applies committed logs
services/raft_services.py - Raft state machine → Snapshot management: creates snapshots
services/raft_services.py - Peer transport → Peer nodes: sends Raft messages
services/cluster_services.py - Log application → Database adapter: updates employees
services/replication_services.py - Raft persistence → Database adapter: executes queries
services/persistence_services.py - Database adapter → MySQL: connects and queries
database/database.py - Service wiring → Database adapter: constructs adapter
services/dependencies.py - Service wiring → Raft persistence: constructs service
services/dependencies.py - Service wiring → Raft state machine: constructs service
services/dependencies.py - Service wiring → Peer transport: constructs service
services/dependencies.py - Service wiring → Snapshot management: constructs service
services/dependencies.py - Service wiring → Node configuration: loads settings
services/dependencies.py