Deploying FerretDB on VPS: The Ultimate Guide to Running MongoDB Syntax on a Truly Open-Source PostgreSQL Backend
Introduction: The Modern Database Dilemma
In the contemporary enterprise landscape, data is the most critical asset. For years, development teams favored MongoDB for its flexible document model, dynamic schemas, and intuitive query syntax. It accelerated MVP development and scaled fluidly. However, the landscape shifted dramatically when MongoDB transitioned from an open-source license to the Server Side Public License (SSPL). This change rendered it non-compliant with Open Source Initiative (OSI) standards, creating compliance risks, vendor lock-in concerns, and rising licensing costs for many enterprises.
Enter FerretDB. Built as a stateless proxy that translates MongoDB wire protocol queries into PostgreSQL-compatible SQL, FerretDB offers a groundbreaking alternative. By utilizing FerretDB, organizations can retain their existing MongoDB codebases, drivers, and tools while storing their underlying data in PostgreSQL—the gold standard of reliable, open-source relational databases. This blog post provides a comprehensive, business-centric guide on how and why to deploy FerretDB on a Virtual Private Server (VPS) to regain true open-source freedom.
---Why Combine MongoDB Syntax with a PostgreSQL Backend?
Choosing a database infrastructure is no longer just a technical decision; it is a strategic business choice. The combination of FerretDB and PostgreSQL offers several compelling advantages for modern enterprises:
- Absolute Open-Source Compliance: PostgreSQL operates under the permissive PostgreSQL License, and FerretDB uses the Apache 2.0 license. This combination ensures your stack remains 100% open-source, eliminating the compliance and legal risks associated with SSPL.
- Cost Efficiency and Infrastructure Consolidation: Instead of maintaining separate clusters for relational data (PostgreSQL) and document data (MongoDB), teams can consolidate their entire data tier onto a single PostgreSQL infrastructure via FerretDB, drastically reducing VPS resource overhead and maintenance costs.
- Familiar Developer Experience: Engineers do not need to learn a new query language or rewrite complex application logic. They continue using standard MongoDB drivers and tools (like
mongoshor Compass), keeping productivity high. - Enterprise-Grade Reliability: PostgreSQL brings decades of engineering excellence, robust ACID compliance, sophisticated indexing options, and highly mature backup/replication ecosystems to your document data.
Architectural Overview: How FerretDB Works
To successfully deploy and manage this solution, it is vital to understand the underlying architecture. FerretDB does not actually store data. Instead, it acts as an analytical and translation layer.
FerretDB operates as a stateless proxy. When your application sends a MongoDB command, FerretDB intercepts it, translates the JSON/BSON document queries into SQL commands, executes them against a PostgreSQL database, and converts the SQL results back into BSON for the application.
Because FerretDB is entirely stateless, it can be easily scaled horizontally or run in a lightweight Docker container on your VPS alongside or separate from your PostgreSQL instance.
---Step-by-Step Deployment Guide on a VPS
Let us explore the technical blueprint for deploying FerretDB on a standard Linux VPS (e.g., Ubuntu 24.04 LTS) using Docker Compose, which represents the most reliable and maintainable deployment methodology.
Prerequisites
Before initiating the deployment, ensure your VPS meets the following baseline requirements:
- A Linux-based VPS with at least 2 vCPUs and 4GB RAM (recommended for production workloads).
- Docker and Docker Compose installed and configured.
- A registered domain name pointing to your VPS IP address (if external/secure access is required).
Step 1: Setting Up the Directory Structure
Log into your VPS via SSH and create a dedicated workspace directory for your database stack:
mkdir -p ~/ferretdb-stack && cd ~/ferretdb-stackStep 2: Configuring the Docker Compose Environment
Create a docker-compose.yml file to define both the PostgreSQL backend container and the FerretDB proxy container. This unified configuration ensures seamless networking between the translation layer and the storage engine.
version: '3.8'
services:
postgres:
image: postgres:16-alpine
container_name: postgres-backend
environment:
POSTGRES_USER: ferret_admin
POSTGRES_PASSWORD: SuperSecurePassword123!
POSTGRES_DB: ferretdb_store
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
restart: always
ferretdb:
image: ghcr.io/ferretdb/ferretdb:latest
container_name: ferret-proxy
environment:
FERRETDB_POSTGRESQL_URL: "postgres://ferret_admin:SuperSecurePassword123!@postgres:5432/ferretdb_store?sslmode=disable"
FERRETDB_LISTEN_ADDR: "0.0.0.0:27017"
ports:
- "27017:27017"
depends_on:
- postgres
restart: always
volumes:
pgdata:Step 3: Launching the Stack
Execute the following command to download the images and run the services in the background:
docker compose up -dVerify that both containers are operating successfully by checking the logs:
docker compose logs -f ferretdb---Verifying the Connection
Once the services are active, you can test the deployment using the standard MongoDB shell (mongosh) either from your local machine or directly on the VPS:
mongosh "mongodb://localhost:27017/test_db"Once connected, test document insertion and retrieval using standard MongoDB syntax:
db.users.insertOne({ name: "John Doe", role: "Enterprise Architect", Active: true });
db.users.find({ name: "John Doe" });Behind the scenes, FerretDB automatically creates a PostgreSQL schema corresponding to your MongoDB database, storing the JSON documents inside PostgreSQL's highly optimized jsonb data type fields.
Production Best Practices for Business Infrastructure
Deploying software on a VPS is straightforward, but optimizing it for enterprise stability requires adherence to industry best practices:
1. Implementing Rigorous Security
Never expose port 27017 or 5432 directly to the public internet without robust authentication and firewall rules. Utilize tools like UFW (Uncomplicated Firewall) to limit access solely to authorized application servers. Furthermore, enable TLS/SSL encryption for production data in transit by configuring reverse proxies like Nginx or Traefik.
2. Automating Backup Cycles
Because your underlying data resides within PostgreSQL, backing up your infrastructure is simple. You do not need complex MongoDB backup tooling; standard enterprise utilities like pg_dump or continuous archiving solutions like pgBackRest work perfectly out of the box, ensuring data durability.
3. Performance Optimization and Indexing
While FerretDB maps MongoDB indexes to PostgreSQL indexes efficiently, deep nesting within JSON data can affect latency at scale. Monitor query speeds and leverage PostgreSQL's advanced performance tuning flags, adjusting parameters such as shared_buffers and work_mem within your PostgreSQL container configuration to maximize processing efficiency.
Conclusion: Securing Data Sovereignty
Transitioning to FerretDB on a VPS represents a strategic milestone for companies seeking to optimize their technological infrastructure. It eliminates licensing uncertainties and costly proprietary scaling traps while fully preserving the beloved, highly productive MongoDB developer workflow. By leveraging the unparalleled reliability of PostgreSQL alongside the elegant translation mechanics of FerretDB, your business builds a scalable, highly secure, and truly open-source foundation prepared for the future.
