Skip to content

Polyglot sidecar deployment: running mixed runtimes on one host

Co-host Node.js, Python, PHP, and Go services on a single Linux VM with systemd, isolated by user and resource group, fronted by a single Nginx.

Most engineering teams accumulate services in different languages over time — the legacy PHP monolith, the Node.js API the new team built, the Go data exporter someone wrote in a hackathon, and a Python ML inference sidecar. The cloud-native answer is “one service per container”, but plenty of teams are not there yet, and a single beefy Linux VM running all four with proper isolation is a perfectly defensible architecture. This article walks through the pattern.

How to verify

Inspect what is co-resident today:

systemctl list-units --type=service --state=running | grep -E "node|python|php|go|rust" | head
sudo ss -lntp | head
sudo systemd-cgls --no-pager | head -40
sudo nginx -T 2>/dev/null | grep -E "^\s*(server_name|listen|proxy_pass)" | head -30
free -h && df -h /

If systemd-cgls shows every service under system.slice with no further grouping, isolation is shallow — one service eating memory can starve every other. Slices are the fix.

What’s happening

systemd has three concepts that make polyglot hosting tenable. Services are the running processes. Slices are nested cgroups that group services by purpose (web.slice, worker.slice, infra.slice) so resource limits apply to the slice and divide among its services. Sandboxing directives (ProtectSystem, PrivateTmp, etc.) isolate services from each other and from the host even when they share a kernel.

Each service runs as its own system user, with its own working directory, its own ports (UNIX socket per service), and is supervised independently. Nginx in front maps incoming hostnames or paths to the right backend. The result is a deployable architecture that looks a lot like Kubernetes minus the orchestration overhead.

Where this falls down: noisy neighbors. A Node service that pegs CPU and a Python service that allocates 8 GiB will fight for shared resources unless you give them explicit limits via cgroup slices and MemoryMax/CPUWeight. Get the isolation right and a 16 vCPU / 32 GiB VM can serve a half-dozen services predictably.

The procedure

  1. Define slices for the major groupings. /etc/systemd/system/web.slice:

    [Slice]
    Description=User-facing web services
    CPUWeight=500
    MemoryMax=20G
    IOWeight=500
    # /etc/systemd/system/worker.slice
    [Slice]
    Description=Background workers and batch
    CPUWeight=200
    MemoryMax=8G
    IOWeight=200

    CPUWeight is a relative share — web.slice gets 500/(500+200) = 71% of CPU under contention, worker.slice gets 29%.

  2. Each service unit declares its slice. A Node API:

    # /etc/systemd/system/api-node.service
    [Service]
    Slice=web.slice
    User=node-api
    WorkingDirectory=/var/www/api
    ExecStart=/home/node-api/.nvm/versions/node/v20.18.0/bin/node server.js
    Environment=PORT=/run/api-node.sock
    MemoryMax=4G
    Restart=on-failure

    A Python inference sidecar:

    # /etc/systemd/system/inference.service
    [Service]
    Slice=worker.slice
    User=inference
    WorkingDirectory=/var/www/inference
    ExecStart=/opt/venvs/inference/bin/python -m gunicorn app:app -b unix:/run/inference.sock
    Environment=MODEL_PATH=/var/lib/inference/model.bin
    MemoryMax=6G
    Restart=on-failure
  3. A single Nginx server block routes by path or hostname:

    upstream api_node    { server unix:/run/api-node.sock; }
    upstream inference   { server unix:/run/inference.sock; }
    upstream php_app     { server unix:/run/php/php8.3-fpm.sock; }
    
    server {
      listen 443 ssl http2;
      server_name app.example.com;
      # ssl_certificate ...
    
      location /api/ {
        proxy_pass http://api_node;
        proxy_set_header Host $host;
      }
    
      location /infer/ {
        proxy_pass http://inference;
        proxy_read_timeout 120s;
      }
    
      location / {
        root /var/www/php-app/public;
        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
      }
    
      location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
      }
    }

    One Nginx, three runtimes, one host, one TLS certificate.

  4. Validate isolation:

    sudo systemd-cgls --no-pager
    # web.slice
    #   ├─ api-node.service
    #   └─ nginx.service
    # worker.slice
    #   └─ inference.service
    sudo systemctl status web.slice
  5. For deploys, treat each service as independent. The Node deploy script touches api-node.service only; the Python deploy touches inference.service; PHP-FPM reloads on php8.3-fpm.service. No deploy of one service ever stops another.

Operational notes

  • Per-service MemoryMax inside a slice with its own MemoryMax means the OOM-killer pressure cascades — a service hitting its limit gets killed first, then the slice limit kicks in if multiple services starve simultaneously. Set both consciously.
  • Shared resources still need coordination. Two services hitting the same Redis instance with no key-namespacing will collide. Conventions (key prefixes per service, separate DBs in Redis) live outside systemd.
  • Log volume from many services adds up — journald defaults retain 10% of disk. On a polyglot host with multiple chatty services, set SystemMaxUse=2G in /etc/systemd/journald.conf explicitly and ship the rest to a log aggregator.
  • Backups must enumerate every service’s data dir — /var/lib/api-node/, /var/lib/inference/, /var/lib/mysql/. A polyglot host with five services has five data root candidates; missing one in the backup script bites at the worst time.
  • Upgrades to one runtime should not require touching others. Pin Node via nvm under the node-api user, Python via venv, PHP via apt — three independent upgrade paths, three independent rollback paths.

The polyglot single-VM pattern is what Stack Harbor’s managed operations practice uses for clients whose service count is in the low single digits but whose runtimes are diverse — the operating cost is much lower than a Kubernetes cluster, and the isolation, if done with slices and sandboxing, is more than sufficient. When the service count grows past 10, the conversation shifts; until then, this architecture earns its keep.