Every new project seems to start with the same architecture diagram: Postgres for data, Redis for cache, RabbitMQ or SQS for jobs, Elasticsearch for search, maybe MongoDB "for the flexible stuff". Five systems to provision, secure, back up, monitor and keep consistent, for an app with three hundred users.
The position: Postgres is enough for far longer than you think. It's a queue, a search engine, a document store and a cache, all with transactions, one backup and one connection string. Add another datastore when Postgres is measurably hurting, not when a blog post says you'll need it "at scale".
The real cost of the extra box
Every additional datastore costs more than its hosting bill:
- Consistency. Write an order to Postgres and a job to Redis. Postgres commits, Redis is unreachable. Now you have an order nobody will ever process. Or the reverse: the job runs before the transaction commits and can't find the row.
- Operations. Another thing to patch, monitor, alert on, upgrade and restore. Another set of credentials. Another failure mode at 3 am.
- Local development and CI. Every service is one more container in
docker compose, one more thing to seed in tests. - Knowledge. Your team needs to understand the failure semantics of each system. Most teams deeply understand one database at best.
When the queue lives in the same database as the data, enqueuing a job is part of the same transaction. Commit the order and the job together, or neither. That one property eliminates a whole category of bugs.
A job queue with SKIP LOCKED
FOR UPDATE SKIP LOCKED (since Postgres 9.5) is what makes a Postgres queue practical. Workers lock the next available row and skip rows other workers already hold, so they never block on each other or grab the same job.
CREATE TABLE jobs (
id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
queue text NOT NULL DEFAULT 'default',
payload jsonb NOT NULL,
run_at timestamptz NOT NULL DEFAULT now(),
attempts int NOT NULL DEFAULT 0
);
CREATE INDEX jobs_ready_idx ON jobs (queue, run_at);
A worker runs this inside a transaction, does the work, then deletes the row and commits:
BEGIN;
SELECT id, payload
FROM jobs
WHERE queue = 'default' AND run_at <= now()
ORDER BY run_at
LIMIT 1
FOR UPDATE SKIP LOCKED;
-- do the work in application code, then:
DELETE FROM jobs WHERE id = $1;
COMMIT;
If the worker crashes mid-job, the transaction rolls back, the lock is released and the job becomes available again. No visibility timeouts, no lost messages. For failures you catch, bump attempts and push run_at forward for a retry with backoff.
The trade-off: the transaction stays open while the job runs, so keep jobs short. For long jobs, claim the row with a locked_until column instead, and reclaim expired ones.
You don't have to build this yourself. In Python, Procrastinate is a Postgres-backed task queue, and since Django 6.0 there's a built-in Tasks API (django.tasks) with database-backed workers available through the django-tasks-db package. Postgres also has LISTEN/NOTIFY for waking workers without polling.
Full-text search that's good enough
Before standing up Elasticsearch, try a generated tsvector column with a GIN index:
ALTER TABLE articles
ADD COLUMN search tsvector GENERATED ALWAYS AS (
setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
setweight(to_tsvector('english', coalesce(body, '')), 'B')
) STORED;
CREATE INDEX articles_search_idx ON articles USING gin (search);
SELECT id, title, ts_rank(search, query) AS rank
FROM articles,
websearch_to_tsquery('english', 'django "service layer" -celery')
AS query
WHERE search @@ query
ORDER BY rank DESC
LIMIT 20;
That gives you stemming ("orders" matches "order"), weighted fields, quoted phrases and exclusions through websearch_to_tsquery, which accepts the kind of syntax people type into search boxes. Add the pg_trgm extension for typo-tolerant matching on names and short strings.
Django supports this directly through django.contrib.postgres.search:
from django.contrib.postgres.search import SearchQuery, SearchRank
from django.db.models import F
query = SearchQuery("django service layer",
search_type="websearch", config="english")
results = (
Article.objects.filter(search=query)
.annotate(rank=SearchRank(F("search"), query))
.order_by("-rank")[:20]
)
It won't match a dedicated search engine on relevance tuning, faceting at huge scale or multi-language analysis. For a product catalogue, a help centre or an admin search box, it's usually plenty.
JSON when the schema really is flexible
jsonb stores JSON in a binary, indexable form. Need to store webhook payloads, per-tenant settings or third-party API responses? You don't need a document database.
CREATE INDEX events_payload_idx ON events USING gin (payload jsonb_path_ops);
SELECT id FROM events WHERE payload @> '{"type": "invoice.paid"}';
In Django, models.JSONField maps to jsonb on Postgres, and lookups like filter(payload__type="invoice.paid") work out of the box.
One warning: jsonb is a pressure valve, not a design. If you're querying the same keys in every request, they're columns. Promote them.
A cache that's one table
For many apps the "cache" is a handful of expensive computed values. Postgres can hold those in an UNLOGGED table, which skips the write-ahead log, so writes are cheaper. The catch is that it's truncated after a crash, which is exactly the durability a cache needs.
CREATE UNLOGGED TABLE cache (
key text PRIMARY KEY,
value jsonb NOT NULL,
expires_at timestamptz NOT NULL
);
INSERT INTO cache (key, value, expires_at)
VALUES ('dashboard:42', '{"orders": 118}', now() + interval '5 minutes')
ON CONFLICT (key) DO UPDATE
SET value = EXCLUDED.value, expires_at = EXCLUDED.expires_at;
Django also ships a database cache backend, django.core.cache.backends.db.DatabaseCache, set up with manage.py createcachetable. Before you add a cache at all, check whether the real fix is an index, a select_related() or a materialized view.
When it actually hurts
I'm not saying never. I'm saying wait for evidence. Signs that it's time:
- Queue throughput. Sustained high job volume where the jobs table churns faster than autovacuum keeps up, and the bloat shows in your metrics. That's when SQS or a dedicated broker earns its keep.
- Cache hit volume. You need very high read rates on hot keys with sub-millisecond latency, and the cache traffic is competing with your real queries for connections and CPU. That's what Redis or Valkey is for.
- Search quality. Users need faceting, synonyms, typo tolerance across large corpora or relevance tuning you can't get from
ts_rank. Bring in OpenSearch, Meilisearch or similar. - Analytics. Large aggregations over hundreds of millions of rows slow down the primary. Move them to a replica first, then to a columnar store if needed.
- Fan-out and streaming. Many consumers replaying an event log is Kafka's job, not a jobs table.
Every one of those is a measurement, not a feeling. Watch query latency, connection count, replication lag, table bloat and CPU. When a specific workload is the cause, extract that workload, and only that one.
Bottom line
Postgres has decades of engineering behind it, transactions across everything you put in it, and one backup story. Start with one database. Use it properly. Add the second system when a graph tells you to, not when a diagram does. Most products never get there, and the ones that do will know exactly which piece to move out.