Back to articles
Technology Insight

Scaling for Profit: How to Run 200 Isolated PocketBase Applications on a Single 4GB RAM VPS using Kamal 2 and Docker Swarm

June 5, 2026

Introduction: The Agency Infrastructure Dilemma

In the competitive landscape of digital agencies, the pressure to balance high performance with cost efficiency is relentless. Traditional deployment models often lead to "resource sprawl," where each client project demands its own dedicated virtual private server (VPS) or expensive managed hosting service. This approach is not only difficult to manage but also eats into the agency's profit margins.

Imagine a scenario where you could host 200 isolated, production-ready applications for various clients on a single, modest VPS with only 4GB of RAM. It sounds like an impossible feat of engineering, but by combining the lightweight efficiency of PocketBase, the orchestration power of Docker Swarm, and the streamlined deployment workflow of Kamal 2, this level of optimization is now within reach.

The Core Technology Stack

To achieve this density, we must select tools that prioritize low overhead and high portability. Our architecture relies on three pillars:

  • PocketBase: An open-source backend consisting of an embedded SQLite database, auth service, and file storage—all contained within a single Go executable.
  • Docker Swarm: A container orchestration tool that is significantly lighter than Kubernetes, making it ideal for managing multiple containers on a single node or small clusters.
  • Kamal 2: The latest deployment tool from 37signals that simplifies deploying and managing web apps in Docker containers without the need for complex PaaS providers.

Why PocketBase is the Secret Weapon

Unlike traditional setups that require a separate web server (Nginx/Apache), a database server (PostgreSQL/MySQL), and a runtime (Node.js/Python), PocketBase is self-contained. In an idle state, a PocketBase instance consumes as little as 15MB to 30MB of RAM.

"By utilizing SQLite’s WAL (Write-Ahead Logging) mode and the efficiency of the Go runtime, PocketBase allows us to achieve high density without the heavy memory footprint of traditional relational database management systems."

For an agency managing dozens of small to medium-sized client sites, these savings are exponential. When multiplied by 200 instances, the baseline memory usage remains well within the 4GB threshold of a standard VPS.

Architecting for Isolation and Density

Resource Constraints and Limits

The key to preventing a single application from crashing the entire server is strict resource allocation. Using Docker Swarm, we can define hard limits for each container:

  • Memory Limit: 16MB to 32MB per instance.
  • CPU Reservation: 0.05 cores per instance.

By enforcing these limits, we ensure that even if one application experiences a traffic spike, the remaining 199 applications remain stable.

Storage Strategy with SQLite

Since PocketBase uses SQLite, each application’s data is stored in a single file. We utilize Docker volumes mapped to the VPS’s NVMe storage, ensuring high I/O performance. This avoids the overhead of managing 200 separate database connections across a network.

Streamlining Workflow with Kamal 2

Kamal 2 acts as the conductor for our deployment. It handles the Zero-Downtime deployments and the configuration of the Thruster proxy. In our high-density setup, Kamal simplifies the process of pushing updates to specific containers without affecting others.

The configuration file (deploy.yml) allows us to define different environments for each client project while pointing to the same physical hardware. Kamal 2’s ability to manage SSH-based deployments eliminates the need for a heavy agent running on the server, further saving precious RAM.

Implementing Docker Swarm for Orchestration

While Kamal handles the deployment, Docker Swarm provides the internal networking and service recovery. If an instance fails, Swarm’s desired state mechanism automatically restarts the container. We use a Reverse Proxy (such as Traefik or Caddy) in front of the Swarm to route incoming traffic based on hostnames to the correct PocketBase container.

This dynamic routing is essential. When a new client is onboarded, we simply deploy a new PocketBase service to the Swarm, and the proxy automatically picks up the new route without requiring a manual restart of the server.

The Economics of the 4GB VPS Strategy

Let’s look at the financial implications for a modern agency:

Metric Traditional Model (Individual VPS) Optimized Model (Kamal + Swarm)
Number of Apps 200 200
Number of Servers 200 (Smallest nodes) 1 (4GB RAM node)
Monthly Cost (Approx.) $800 - $1,200 $20 - $40
Management Overhead High (200 OS updates) Low (Single OS update)

The cost reduction is staggering—over 95% savings in monthly infrastructure spend. This allows agencies to offer competitive pricing to clients while maintaining higher internal margins.

Monitoring and Security Considerations

High density does not mean high risk. Security remains a priority:

  1. Container Isolation: Each PocketBase instance runs in its own Docker namespace, ensuring that client A cannot access client B’s data.
  2. Automated Backups: Using S3-compatible storage (like Cloudflare R2 or MinIO), we schedule automated backups of the SQLite database files.
  3. Health Checks: We implement Docker health checks to monitor the responsiveness of each app, allowing the Swarm to self-heal.

Conclusion: Future-Proofing Your Agency

Optimizing infrastructure is no longer just a technical challenge; it is a strategic business advantage. By leveraging Kamal 2, Docker Swarm, and PocketBase, agencies can move away from bloated, expensive hosting and toward a lean, automated, and highly profitable deployment engine.

As you scale, this architecture grows with you. If 200 apps eventually exceed the 4GB limit, Docker Swarm makes it trivial to add a second node and transform your single VPS into a multi-node cluster, ensuring your agency stays agile and cost-effective for years to come.