A distributed database system with one Coordinator and multiple Workers, supporting horizontal and vertical fragmentation, replication, and distributed query execution.
┌─────────────────┐
│ Coordinator │ - Query distribution
│ │ - Metadata management
│ │ - Worker coordination
└────────┬────────┘
│
┌────┴────┐
│ │
┌───▼───┐ ┌──▼────┐
│Worker1│ │Worker2│ - Query execution
│ │ │ │ - Data storage
│ │ │ │ - Local database management
└───────┘ └───────┘
Coordinator
- Distributes queries to appropriate workers
- Manages distribution metadata
- Tracks table fragmentation and replication
- Monitors worker health
Workers
- Execute SQL queries locally
- Manage local PostgreSQL databases
- Store table data
- Report status to coordinator
- ✅ Distributed Query Execution: Queries distributed across multiple workers
- ✅ Horizontal Fragmentation: Split tables by rows based on conditions
- ✅ Vertical Fragmentation: Split tables by columns
- ✅ Table Replication: Full replication across workers
- ✅ Metadata Management: Automatic tracking of data distribution
- ✅ Health Monitoring: Automatic worker health checks
- ✅ Inline Fragmentation: Configure fragmentation in CREATE TABLE command
- Java 11 or higher
- Gradle (included via wrapper)
.\build-all.bat# Terminal 1 - Worker 1
.\start-worker-1.bat
# Terminal 2 - Worker 2
.\start-worker-2.bat# Terminal 3 - Coordinator
.\start-coordinator.batSQL> status
SQL> CREATE DATABASE shop;
SQL> USE shop;
SQL> CREATE TABLE products (id INT, name VARCHAR, price INT) ON worker-1, worker-2;
SQL> INSERT INTO products VALUES (1, 'Laptop', 1000);
SQL> SELECT * FROM products;
SQL> SHOW METADATA;File: Coordinator/workers.config
# Format: workerId,host,port
worker-1,localhost,8081
worker-2,localhost,8082
For distributed VMs:
worker-1,192.168.1.101,8081
worker-2,192.168.1.102,8082
File: Worker/worker.config
workerId=worker-1
port=8081
CREATE DATABASE ecommerce;
USE ecommerce;
CREATE TABLE products (
id INT,
name VARCHAR,
price INT
) ON worker-1, worker-2;
INSERT INTO products VALUES (1, 'Laptop', 1000);
SELECT * FROM products;-- Split orders by ID range
CREATE TABLE orders (
id INT,
customer_id INT,
total INT
) ON worker-1, worker-2
HORIZONTAL id RANGE
worker-1: id <= 1000,
worker-2: id > 1000;
-- Data automatically routed to correct worker
INSERT INTO orders VALUES (500, 1, 250); -- Goes to worker-1
INSERT INTO orders VALUES (1500, 2, 350); -- Goes to worker-2-- Split user data by columns
CREATE TABLE users (
id INT,
name VARCHAR,
email VARCHAR,
address VARCHAR,
phone VARCHAR
) ON worker-1, worker-2
VERTICAL
worker-1: id,name,email,
worker-2: id,address,phone;
INSERT INTO users VALUES (1, 'John', 'john@email.com', '123 St', '555-1234');
SELECT * FROM users;-- Create table
CREATE TABLE categories (id INT, name VARCHAR) ON worker-1, worker-2;
-- Enable full replication
REPLICATE TABLE categories ON worker-1, worker-2;
-- Data now stored on all workers
INSERT INTO categories VALUES (1, 'Electronics');See COMMANDS.md for complete command reference.
status- Show worker statusshow metadata- Display distribution metadatahelp- Show available commandsexit/quit- Exit coordinator
SHOW DATABASESCREATE DATABASE <name>USE <database>DROP DATABASE <name>
CREATE TABLE <name> (<columns>) ON <workers>CREATE TABLE ... HORIZONTAL ... RANGE ...CREATE TABLE ... VERTICAL ...DROP TABLE <name>DESCRIBE <name>
INSERT INTO <table> VALUES (...)SELECT * FROM <table>UPDATE <table> SET ... WHERE ...DELETE FROM <table> WHERE ...
REPLICATE TABLE <name> ON <workers>FRAGMENT TABLE <name> HORIZONTAL ...FRAGMENT TABLE <name> VERTICAL ...
See DEPLOYMENT_GUIDE.md for detailed deployment instructions including:
- Local testing setup
- Multi-VM deployment
- Network configuration
- Firewall settings
- Production deployment
DBMS_Project/
├── Coordinator/
│ ├── src/main/java/org/example/
│ │ ├── Main.java
│ │ ├── service/
│ │ │ ├── DistributedQueryCoordinator.java
│ │ │ ├── WorkerCommunicationService.java
│ │ │ ├── WorkerRegistry.java
│ │ │ └── MetadataManager.java
│ │ ├── model/
│ │ │ ├── WorkerNode.java
│ │ │ ├── DistributedMetadata.java
│ │ │ └── TableMetadata.java
│ │ └── ui/
│ │ └── ConsoleUserInterface.java
│ ├── data/db/metadata.json
│ ├── workers.config
│ └── build.gradle
│
├── Worker/
│ ├── src/main/java/org/example/
│ │ ├── Main.java
│ │ ├── server/
│ │ │ └── WorkerHttpServer.java
│ │ └── service/
│ │ └── PostgresqlQueryService.java
│ ├── worker.config
│ └── build.gradle
│
├── COMMANDS.md # Command reference
├── DEPLOYMENT_GUIDE.md # Deployment instructions
├── README.md # This file
├── build-all.bat # Build all components
├── start-coordinator.bat # Start coordinator
├── start-worker-1.bat # Start worker 1
└── start-worker-2.bat # Start worker 2
- Splits table rows based on conditions
- Each worker stores a subset of rows
- Useful for range-based queries
- Example: Orders split by date or ID range
- Splits table columns across workers
- Each worker stores a subset of columns
- Primary key included in all fragments
- Useful for wide tables with column-based access
- Full copy of table on all workers
- Useful for small, frequently-accessed tables
- Improves read performance
- Example: Categories, configuration tables
- Tracks table distribution automatically
- Stored in
Coordinator/data/db/metadata.json - Updated only when all workers succeed
- View with
SHOW METADATAcommand
- Check if workers are running:
status - Verify
workers.confighas correct IPs and ports - Check firewall settings
- Verify network connectivity
- Run
USE <database>;before table operations
- Check worker status with
statuscommand - Restart inactive workers
- Verify worker configuration
- Ensure all workers succeeded (check output)
- Verify
data/db/metadata.jsonexists - Restart coordinator if needed
# Build coordinator
cd Coordinator
.\gradlew.bat build
# Build worker
cd Worker
.\gradlew.bat buildcd Coordinator
.\gradlew.bat test
cd Worker
.\gradlew.bat test- Sanif Ali Momin - Developer and Contributor
- Mostafaa Abdelaziz - Developer and Contributor
This project is for educational purposes.
- COMMANDS.md - Complete command reference with examples
- DEPLOYMENT_GUIDE.md - Deployment instructions for local and distributed setups
For issues or questions:
- Check COMMANDS.md for command syntax
- Check DEPLOYMENT_GUIDE.md for setup issues
- Verify worker status with
statuscommand - Check metadata with
SHOW METADATAcommand