A small application can receive only a handful of HTTP requests and still need infrastructure that runs continuously. An Express endpoint may create orders, a background worker may process them, and Postgres must preserve both the business records and the work waiting to happen. Low traffic describes the request rate. It does not describe the application's operating requirements.

That distinction appeared in an r/node hosting question: the application was inexpensive to serve, but its worker polled an outbox every five seconds and could not sleep. Picking the cheapest advertised web-service tier would leave an important part of the system out of the calculation.

Our recommendation is to price and deploy the complete system. For an application you can operate yourself, a small VPS with separate API, worker, and database containers is a reasonable starting point. If operating the database is an unwelcome responsibility, compare managed services using the same workload and recovery requirements. Keep the application portable enough to move when those requirements change.

Download the complete runnable examples, including setup instructions and verification commands.

Define what has to stay awake

Start with a written operating contract. How quickly must queued work begin? Can processing wait five minutes? What happens if the worker stops overnight? How much recently accepted data can the business afford to lose? Who receives the alert when a backup fails?

These answers affect the deployment more than an early estimate of monthly page views. A report generator that can run every hour is a different service from a payment reconciliation worker with a short deadline. Scheduling a batch invocation may suit the first. A continuously running process may suit the second.

Also identify where work originates. If every job starts with an HTTP request, the request can persist a durable job and a suitable mechanism can wake a processor. If jobs originate outside the web application, sleeping the web process tells you little about whether processing is available. A health-check ping is a poor substitute for a documented execution model.

Render's worker documentation describes background workers as continuously running services without incoming network traffic. That is the category to compare against your requirements. A web service's free allowance or sleep policy does not automatically describe its background-worker offering.

Budget for the whole deployment

Write down six cost categories: application compute, database compute, durable storage, backups, network transfer, and operating time. Add a separate line for temporary duplication during deploys or recovery. A bill that fits only while every component remains at its smallest allocation has little room for mistakes.

For a concrete reference, Railway's pricing page, checked on October 27, 2026, lists a Hobby minimum of $5 with $5 of included monthly usage credits; usage beyond that allowance costs extra. That is a pricing model, not a promise that your API, worker, database, and storage will together cost $5. Recheck the live calculator before deploying this article's example.

Avoid comparing that minimum against a VPS quote that excludes backups, an address surcharge, taxes, or the storage you need. Region and currency matter. A provider's attractive introductory credit is useful for experimentation, but your steady-state budget should also work after the credit expires.

A simple cost worksheet is more useful than a universal winner:

Cost item Managed services One VPS
API and worker Price both processes and their resources Share a measured compute budget
Postgres Check service size, storage, and connections Reserve memory and disk explicitly
Recovery Check retention and restore capabilities Fund off-host storage and restore work
Operations Review what the provider actually handles Own host updates, database care, and recovery

These are responsibility categories, not equivalent reliability guarantees. A single VPS remains a single failure domain. Several managed services can also share a region or dependency. State the failure you are paying to survive before paying for redundancy.

Comparison of managed services and a single VPS across compute, database care, recovery, and operations.

Compare the full operating responsibility alongside the invoice. Exact prices depend on region, resources, and the current provider plan.

Use three processes and one durable work boundary

The example application accepts an order, saves it, and prepares a receipt asynchronously. The API and worker run as different processes, even when they share a machine. Restarting the API should not require duplicating a worker inside every new web process.

Postgres contains three tables. orders holds accepted business records. outbox records which orders need processing. receipts contains the prepared result. Creating the order and its outbox row happens in one transaction, so a crash cannot leave an accepted order without its corresponding work item.

For clarity, the example's background effect stays inside the database. It prepares a receipt record; it does not send an email or charge a card. Keeping that boundary explicit prevents a common mistake: assuming a database transaction can roll back an external API request.

A browser calls the Express API, which commits an order and outbox row; a separate worker creates a receipt in Postgres; backups are stored outside the host.

The request persists the work before returning. The worker processes committed work independently, and recovery data lives outside the application host.

Use a caller-generated UUID as the order identifier. Retrying the same identifier with the same description returns the existing order. Reusing it with different content returns a conflict. That gives the HTTP operation a clear retry contract instead of relying on clients never sending a request twice.

// core.mjs — excerpt from createOrder(pool, id, description)
await client.query('BEGIN');
const result = await client.query(
  `INSERT INTO orders(id, description) VALUES ($1,$2)
   ON CONFLICT (id) DO NOTHING RETURNING id`,
  [id, description]
);
// The complete example rejects a reused ID with different content.
await client.query(
  `INSERT INTO outbox(order_id) VALUES ($1)
   ON CONFLICT (order_id) DO NOTHING`,
  [id]
);
await client.query('COMMIT');

The complete implementation includes rollback and releases the checked-out connection in a finally block. The excerpt illustrates the atomic boundary; it is not a replacement for the surrounding error handling. SQL parameters keep user input separate from the statement text.

Make the worker safe before making it fast

A worker should process committed jobs without overlapping its own polling iterations. Use an awaited loop rather than an interval that can start another invocation while a previous one is still waiting for the database. When there is no work, wait briefly. After an unexpected failure, log the error and delay the next attempt.

The example selects one pending outbox row with a lock, prepares the receipt, and marks the row processed in the same transaction. A second worker can skip the locked row and claim a different one. PostgreSQL documents SKIP LOCKED as appropriate for queue-like access, while warning that it gives an inconsistent view for ordinary queries. Here that tradeoff is intentional.

BEGIN;
SELECT id, order_id
FROM outbox
WHERE processed_at IS NULL
ORDER BY id
LIMIT 1
FOR UPDATE SKIP LOCKED;
-- Insert the receipt using the selected order_id.
-- Mark that outbox row processed, then commit.
COMMIT;

The receipt's unique order key provides another check against duplication. If the transaction fails before commit, both its receipt change and completion mark roll back. When it commits, both become visible together. That guarantee covers these database writes, rather than arbitrary effects outside Postgres.

If your real worker calls a mail or billing provider, change the design deliberately. Claim a job with a lease, commit the claim, perform the bounded external call, and record its outcome. Use a stable idempotency key if the provider supports one. A crash after the provider accepts the call but before your completion write creates an ambiguous result, so reconciliation is part of the design.

Add retry limits and a dead-letter state before adopting that external-work variant. One permanently invalid job should not consume every polling cycle. Track attempts, the next eligible time, the most recent failure, and an operator action for retrying or cancelling the job. The small database-only example does not pretend to implement that complete queue product.

Put the stack in Compose

Use one application image with different commands for the API and worker. Persist the database in a named volume. Bind the API port to the host's loopback interface and put a TLS reverse proxy in front of it. Leave the database port unpublished.

services:
  api:
    build: .
    command: ["node", "api.mjs"]
    ports: ["127.0.0.1:3000:3000"]
    environment:
      DATABASE_URL: postgres://app:${POSTGRES_PASSWORD}@db:5432/app
    depends_on:
      db:
        condition: service_healthy
  worker:
    build: .
    command: ["node", "worker.mjs"]
    environment:
      DATABASE_URL: postgres://app:${POSTGRES_PASSWORD}@db:5432/app
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres:17-bookworm
    environment:
      POSTGRES_USER: app
      POSTGRES_DB: app
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pgdata:/var/lib/postgresql/data
      - ./schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U app -d app"]
      interval: 5s
      timeout: 3s
      retries: 10
volumes:
  pgdata:

The complete example adds process initialization, restart policies, and a shutdown grace period. It also requires a nonempty database password. Use a randomly generated URL-safe value for this connection-string example, keep the environment file out of Git, and use your platform's secret store when available.

Docker's startup-order documentation explains why a running container is different from a ready service. The database health check addresses initial startup ordering. Applications still need sensible timeouts and recovery behavior when the database becomes unavailable later.

The demo uses the database initialization account to keep setup short. Before production, create a separate application role with only the required table and sequence permissions, and reserve schema changes for a migration role. The example endpoint also needs your authentication and abuse controls before it becomes public.

The schema initialization mount runs when Postgres initializes an empty data directory. It is not a migration mechanism for an existing deployment. Apply subsequent schema changes through reviewed migrations, with a rollback or forward-repair plan. Build and deploy an immutable application image instead of editing source files on the server.

Keep the connection budget small

Every API replica and worker process has its own connection pool. If four API processes each permit ten connections and two workers each permit ten more, you have allowed sixty application connections before accounting for migrations, monitoring, or deploy overlap.

The example starts with a maximum of four connections for the API and two for the worker. Those values are a conservative example, not a capacity recommendation. Measure query latency, pool wait time, active connections, and memory before increasing them. A tiny database can run out of useful resources long before the web tier seems busy.

The node-postgres pooling guide emphasizes returning checked-out clients. Use one pool per process, a connection-acquisition timeout, and a statement timeout appropriate to the work. Handle idle-client errors, and call pool.end() during shutdown after ongoing operations finish. Increasing pool size will not repair a leaked connection.

Treat backups as a recovery procedure

A named Docker volume survives a routine container replacement. It does not protect you when the server's disk disappears, an operator deletes data, or a bad migration commits. Recovery needs another copy outside that failure domain and a procedure you have actually tried.

PostgreSQL's backup overview distinguishes logical dumps, file-system approaches, and continuous archiving. Select the method against your acceptable data-loss interval and restore time. If losing a day's accepted work is unacceptable, a nightly dump alone cannot meet your requirement.

For a small application's restore drill, a custom-format logical dump is useful:

# Run in examples/ with the Compose database already healthy.
docker compose exec -T db pg_dump -U app -d app -Fc > app.dump
# Restore into a separate database, never overwrite the live one for a drill.
docker compose exec -T db createdb -U app restore_check
docker compose exec -T db pg_restore -U app -d restore_check --no-owner < app.dump

The pg_dump documentation explains consistent exports and archive restoration. A dump of one database also needs a plan for cluster-level roles and other operational configuration. Use compatible client versions, inspect command failures, encrypt stored backups, and test recovery on a separate host as well as a separate database.

Do not leave the only dump beside the production volume. Automate transfer to off-host storage, retention, and failure alerts. Record how long a full restore takes and verify actual application records afterward. A completed upload tells you a file exists; it does not tell you that your application can use it.

Verify the deployment with failure cases

A successful HTTP response proves only one path. Submit the same order twice and verify that it produces one business record and one outbox row. Submit the same identifier with different content and verify a conflict. Stop the worker, accept several orders, restart it, and confirm that pending work completes.

Then run two workers concurrently and verify that each order has exactly one prepared receipt. Interrupt a transaction before commit and check that no partial order or outbox item remains. The included integration test exercises these database semantics against a disposable Postgres database. It is separate from a hosted-provider performance test.

Monitor pending-job age in addition to queue length. One old job may matter more than a large batch of fresh jobs. Watch disk usage, database availability, backup freshness, process restarts, and request failures. Add an external check so the machine's own monitoring is not your only evidence that it remains reachable.

Choose the next change from measured pressure

Start with the deployment whose responsibilities you can meet. A single VPS can be economical when the workload fits and someone owns recovery. Managed services can justify their invoice when they remove work your team would otherwise struggle to perform reliably.

Move the database when its recovery needs or operating burden warrant it. Add worker capacity when processing delay warrants it. Add API replicas when measured demand warrants them, accounting for connection and deployment overlap. Each change should solve a specific problem while preserving the durable boundary between accepting work and completing it.

The useful outcome is an application whose bill, failure behavior, and maintenance needs you understand. Keep the deployment files, recovery instructions, and test cases together so that the next person can operate the system as confidently as the person who built it.