Varun
Back to Project

ShadowDB

ShadowDB is a comprehensive, enterprise-grade PostgreSQL database management platform that combines high availability clustering, containerized deployments, and a modern web interface to provide developers and organizations with a robust database-as-a-service solution.

ShadowDB
Problem Statement

For developers and businesses building scalable applications, managing the underlying database infrastructure is a complex, time-consuming, and resource-intensive process. This often involves manually configuring, scaling, and maintaining multiple disparate technologies for load balancing, caching, and connection pooling, which detracts from the primary focus of application development and can lead to performance bottlenecks, reliability issues, and security vulnerabilities.

Proposed Solution & Key Features

ShadowDb is designed to be a fully managed, production-ready database service that combines the power of PostgreSQL with Haproxy load balancing, built-in PgPool caching and Connection Pooling. We focus on performance, scalability, and ease of use, allowing developers to focus on building applications without worrying about database management.

Key Features

Patroni-powered clustering with automatic failover and distributed consensus
Multi-node replication (1 primary & 2+ read replicas)
Containerized Infrastructure
One-click database provisioning and management
Manage backups, restores, and PostgreSQL configuration
User and role management with detailed permissions
System Design

Architecture

A multi-tenant, containerized infrastructure managed via a Next.js web application. It uses Docker Compose for instance orchestration, with HAProxy for write-routing and Pgpool for connection pooling and read-routing. ETCD is used for service discovery and configuration management, ensuring high availability.

Database Design

A high-availability PostgreSQL cluster managed by Patroni. The cluster consists of a Primary DB for write operations and multiple Replica DBs for read operations, with data synchronized via real-time streaming replication. This setup ensures both load balancing and automatic failover.

Real-time Features

Real-time data integrity is maintained through PostgreSQL's streaming replication, which continuously pushes data from the primary to the replica databases. The Patroni managers monitor the cluster's health in real-time to trigger failovers instantly upon detecting a failure.

Technology Stack

Frontend

Next.js
TypeScript
Tailwind CSS

Backend

Next.js API Routes
NextAuth

Database

PostgreSQL Cluster
Patroni
PgPool
HAProxy
ETCD

Orchestration

Docker
Patroni
HAProxy
PgPool
ETCD
PostgreSQL

Deployment

DigitalOcean
virtual machines
Technical Challenges

Tiered Resource Management

Allocating specific computational resources, like CPU and RAM, to each database cluster based on the customer's subscription tier to ensure premium users receive more powerful instances.

Solution:

Enhanced the orchestration service to use different Docker Compose templates with predefined resource limits. When provisioning a cluster, the service selects the appropriate template based on the user's tier, automatically enforcing resource allocation.

Secure Role-Based Management

Ensuring that user roles within PostgreSQL are configured securely, preventing any role from having excessive or risky permissions that could compromise data security.

Solution:

Developed a permission management system with predefined, least-privilege roles. Created an automated process within the orchestration layer to manage role assignments and audit permissions.

Dynamic Cluster Orchestration

The need to dynamically create, configure, and manage entire high-availability PostgreSQL clusters on-demand to support a multi-tenant architecture.

Solution:

Built a custom orchestration service that uses Docker Compose and Patroni templates to programmatically provision new, isolated PostgreSQL clusters, using ETCD for configuration and automatic failover.

Frequently Asked Questions

Timeline

3 months

2025

Team

Team of 1

Technologies

Next.js
Orchestration
PostgreSQL
+2