Back to articles
Technology Insight

Scaling MongoDB Apps Seamlessly: A Comprehensive Guide to Deploying FerretDB on a VPS with PostgreSQL Backend

May 30, 2026

Introduction: The Open-Source NoSQL Dilemma

For years, developers have favored MongoDB for its flexible document model, intuitive syntax, and rapid prototyping capabilities. However, changes in MongoDB’s licensing model (the shift to the Server Side Public License, or SSPL) have created compliance and strategic challenges for modern enterprises. Many organizations find themselves caught between a rock and a hard place: they love the MongoDB API and developer experience, but their infrastructure standards mandate true open-source compliance, predictable licensing, and the absolute data durability of relational databases.

Enter FerretDB. FerretDB serves as an open-source, drop-in replacement for MongoDB that translates MongoDB wire protocol queries into SQL, storing the actual data securely within a PostgreSQL backend. This innovative architecture allows engineering teams to keep their existing codebases entirely unchanged while inheriting the enterprise-grade reliability, ACID compliance, and robust ecosystem of Postgres. In this comprehensive guide, we will explore the architectural advantages of this paradigm and provide a production-ready blueprint for deploying FerretDB on a Virtual Private Server (VPS).

Why Combine MongoDB Syntax with PostgreSQL Storage?

Before diving into the deployment mechanics, it is essential to understand the strategic and technical advantages of running FerretDB backed by PostgreSQL on your own VPS infrastructure.

1. True Open-Source Freedom

Unlike MongoDB's SSPL, FerretDB is distributed under the Apache 2.0 license, and PostgreSQL utilizes the PostgreSQL License (a liberal Open Source license similar to BSD or MIT). This ensures your stack remains 100% open-source, eliminating compliance risks and vendor lock-in, making it perfectly suited for enterprise applications and SaaS platforms alike.

2. Uncompromising Data Durability

PostgreSQL is widely regarded as one of the most stable, reliable, and mathematically sound relational database management systems available. By routing your document queries to a Postgres backend, you gain access to:

  • Strict ACID compliance for reliable transaction processing.
  • Advanced write-ahead logging (WAL) for bulletproof crash recovery.
  • A massive ecosystem of mature tooling for backups, point-in-time recovery (PITR), and high availability.

3. Infrastructure Consolidation

Many modern applications require both relational data (for financial transactions, user accounts, and structured reporting) and document data (for flexible user profiles, activity logs, or dynamic configurations). Running FerretDB allows you to consolidate your infrastructure. You can run a single, highly-optimized PostgreSQL cluster that serves both standard relational workloads and NoSQL document workloads simultaneously, dramatically reducing your operational overhead and cloud spend.

Architecture Overview: How FerretDB Bridges the Gap

FerretDB acts as a stateless proxy layer. When your application sends a standard MongoDB command (such as db.collection.find() or db.collection.insertOne()) via standard MongoDB drivers, FerretDB intercepts the communication protocol. It parses the BSON data, translates the query into highly optimized PostgreSQL JSONB queries, executes them against the Postgres database, and formats the relational results back into standard MongoDB wire protocol responses.

Key Architecture Insight: Because FerretDB utilizes PostgreSQL's native JSONB data type, it retains the schema-agnostic flexibility of a traditional document store while utilizing the robust indexing and query execution engines built into Postgres.

Prerequisites for VPS Deployment

To successfully deploy this solution, ensure your Virtual Private Server meets the following baseline requirements:

  • Operating System: Ubuntu 22.04 LTS or Ubuntu 24.04 LTS (clean installation recommended).
  • Hardware Resources: Minimum 2 vCPUs, 2GB RAM, and SSD storage (scale upwards based on your anticipated concurrent connections and dataset size).
  • Access Rights: Root or a user with full sudo privileges.
  • Software: Docker and Docker Compose installed on the host machine.

Step-by-Step Production Deployment Blueprint

While FerretDB can be installed via native packages, utilizing Docker Compose is the industry standard for ensuring isolated, reproducible, and easily maintainable deployments. Follow these steps to spin up your production environment.

Step 1: System Preparation and Directory Structure

First, log into your VPS via SSH and create a dedicated directory structure to keep your database configurations and persistent data organized.

mkdir -p ~/ferretdb-stack/postgres_data
cd ~/ferretdb-stack

Step 2: Crafting the Docker Compose Configuration

Create a docker-compose.yml file within your newly created directory. This file will orchestrate the network communication between the FerretDB proxy and the underlying PostgreSQL engine.version: '3.8' services: postgres: image: postgres:16-alpine container_name: ferretdb-postgres environment: POSTGRES_USER: ferret_admin POSTGRES_PASSWORD: SuperSecurePassword123! POSTGRES_DB: ferretdb_backend volumes: - ./postgres_data:/var/lib/postgresql/data ports: - "127.0.0.1:5432:5432" networks: - database-net restart: always ferretdb: image: ghcr.io/ferretdb/ferretdb:latest container_name: ferretdb-proxy environment: FERRETDB_POSTGRESQL_URL: "postgres://ferret_admin:SuperSecurePassword123!@postgres:5432/ferretdb_backend" FERRETDB_LISTEN_ADDR: "0.0.0.0:27017" ports: - "27017:27017" depends_on: - postgres networks: - database-net restart: always networks: database-net: driver: bridge

Security Warning: In a production environment, ensure you change the POSTGRES_PASSWORD value to a cryptographically secure random string. Additionally, if your application runs on the same VPS, bind FerretDB to 127.0.0.1:27017 instead of 0.0.0.0:27017 to prevent unauthorized external access.

Step 3: Launching the Stack

With the configuration file safely populated, initialize and run your containers in detached mode:

docker compose up -d

Verify that both containers are active and healthy by inspecting the running processes:

docker compose ps

Verifying the Connection and MongoDB Compatibility

To confirm that FerretDB is correctly translating MongoDB syntax into PostgreSQL storage, you can test the connection using the standard MongoDB Shell (mongosh) or via a quick Node.js test script.

Connecting via MongoDB Shell

If you have mongosh installed locally or on your server, connect to your VPS IP address using standard MongoDB connection strings:

mongosh "mongodb://localhost:27017/?authMechanism=PLAIN"

Once connected, execute standard NoSQL commands to insert and query data:

use enterprise_app;

db.customers.insertOne({
  name: "Acme Corporation",
  industry: "Technology",
  active: true,
  metadata: { employees: 250, location: "Global" }
});

db.customers.find({ "metadata.employees": { $gt: 200 } }).pretty();

Behind the scenes, FerretDB automatically provisions a schema named enterprise_app inside your ferretdb_backend PostgreSQL database, creating tables corresponding to your collections and placing the attributes perfectly inside a JSONB column.

Production Considerations and Best Practices

Deploying software on a VPS requires careful attention to long-term reliability, monitoring, and security. Keep these best practices in mind when managing your FerretDB stack:

1. Firewall Hardening

Never leave port 27017 wide open to the public internet without strict network access control lists (ACLs). Use native firewall tools like UFW (Uncomplicated Firewall) on Ubuntu to restrict access exclusively to the IP addresses of your application servers:

sudo ufw allow from YOUR_APP_SERVER_IP to any port 27017 comment 'Allow Application to reach FerretDB'

2. Indexing Strategy

While FerretDB handles routine queries exceptionally well, complex aggregations require proper indexing. FerretDB automatically translates standard MongoDB index commands (e.g., db.collection.createIndex()) into native PostgreSQL indexes on JSONB fields. Ensure you analyze slow queries and apply indexes aggressively on fields used frequently in search criteria.

3. Regular Automated Backups

Because your data resides entirely in PostgreSQL, you do not need complex, fragile NoSQL backup tools. You can rely entirely on standard, time-tested utility commands like pg_dump or enterprise tooling like pgBackRest to secure your database states without locking collections or causing severe performance degradation.

Conclusion: The Best of Both Worlds

Deploying FerretDB on a VPS offers an elegant, highly performant engineering compromise for modern businesses. It respects the developer's preference for agile, document-based NoSQL development while completely satisfying the enterprise requirements of system administrators who demand the rigorous, stable, and truly open-source foundation of PostgreSQL.

By migrating your workloads to FerretDB, you break free from restrictive commercial source-available licenses, simplify your data infrastructure, and retain absolute control over your deployment environment. Whether you are scaling a growing startup or optimizing infrastructure costs for an established product, the combination of MongoDB syntax and PostgreSQL durability provides a future-proof roadmap for your data layer.

Scaling MongoDB Apps Seamlessly: A Comprehensive Guide to Deploying FerretDB on a VPS with PostgreSQL Backend | DPTCloud