Everyone says it like Redis and a database are two different things. They are not. Redis IS a database - it calls itself “the world’s fastest in-memory database”. The real question is which kind, for which job.
WHERE THE DATASET LIVES
Redis keeps it in RAM. Postgres keeps it in files on disk and pulls pages into shared_buffers as needed. Both cache in memory; only one is memory-first by design.
THE PROPERTY THAT GIVES IT AWAY
A Redis key can carry a TTL. Run TTL user:42 and it counts down; at zero the key is gone (-1 means no expiry). A Postgres row has no such thing - it stays until something deletes it. That one property is why Redis can hold a copy you are allowed to lose.
HOW YOU GET A ROW
GET user:42 is a hash lookup - the docs list GET and HGET as O(1).
SELECT * FROM users WHERE id=42 goes through a pipeline. The PostgreSQL docs name the stages: the parser builds a query tree, the rewrite system applies rules, the planner creates every path that leads to the same result and the cheapest one is chosen, then the executor walks the plan. That pipeline is the price of being able to ask anything you want.
WHAT YOU CAN ASK
Redis addresses data by key. GET plan:pro returns (nil) - not a failure, just no key with that name. Core Redis will not scan values for you.
Postgres answers SELECT * FROM users WHERE plan=‘pro’ by any column, with sorting, joins and grouping.
Worth knowing: Redis has a query engine with secondary indexes over hashes and JSON - an index you choose to build, not something SELECT gives you free.
PERSISTENCE
Redis has RDB snapshots and AOF, but the docs warn snapshotting “is not very durable” and you can switch it off entirely.
WHY YOU ADD IT AT ALL
Speed. That is the whole reason. The same answer comes back out of RAM instead of going through that pipeline. It ends up carrying queues, locks and pub/sub too - but latency is what earns it a place in the stack.
Postgres holds the truth. Redis holds a fast copy you are allowed to lose. If Redis vanished right now your app should get slower, not wrong.
#redis #postgres #backendtips #systemdesign
Postgres is the goat, but only if your properly tune its memory allocation
#postgres #coding #programming #softwareengineer #devops
AI Engineering in 2021 vs 2026
[claude code, vscode, postgres, data science, github, fastapi, python, django]
Stop paying for Redis, Elasticsearch, and MongoDB. Postgres does it all. 🐘
Full-text search? tsvector. Job queues? SELECT FOR UPDATE. NoSQL documents? JSONB. AI embeddings? pgvector. Pub/sub? LISTEN/NOTIFY. Cron jobs? pg_cron. Geospatial? PostGIS.
One database. Seven superpowers. Zero extra bills.
Save this before you spin up another service you don’t need 📌
#postgres #postgresql #database #backend #webdevelopment softwaredeveloper programming techreels redis mongodb elasticsearch devtools systemdesign codinglife developertips
A failed Postgres index migration can leave behind an invalid index that hurts writes without helping reads. Here’s why and what to do about it
Did you miss the backend content?
#programming #coding #tech #software
Why devs love Postgres 👨🏽💻👀
#softwareengineering #dev
Everyone calls PostgreSQL a SQL database. So I put 500,000 JSON documents in it.
No schema. No columns. Just raw JSON — exactly what you'd store in MongoDB.
Then I searched inside those documents: 33ms, reading all 500,000 one by one.
Then one line — CREATE INDEX ... USING GIN — and the same search runs in 5ms. Almost 7x faster. And that index doesn't just point at rows; it indexes the keys and values inside the JSON itself.
Relational AND a document store. Joins, transactions, and JSON all at once. Since 1986 — older than almost every database built to replace it.
That's why engineers keep saying the same four words: just use Postgres.
All numbers measured live on PostgreSQL 18.1.
#postgresql #postgres #database #sql #jsonb #nosql #backend #softwareengineering #coding #programming #devtips #webdev #dataengineering #tech
Ten million rows.
Four second queries.
When single Postgres is not enough.
-MM
#sharding #database #postgres #vibecoders #scaling
Your cache doesn't make the first read faster. It can only make the second one faster.
Watch the loop. Three layers: your app at the top, Redis in the middle, Postgres at the bottom. A read falls down through them, and how far it has to fall is what it costs you.
The first read is a miss. The cache is empty, so the request drops straight past Redis — nothing there — and keeps going all the way to disk. Postgres has the row. The answer climbs back up, and on the way past Redis it drops off a copy.
That copy is the whole point. Nobody asked for it. The first reader paid full price and got nothing back for it except a warm cache for everybody behind them.
Now the next two reads stop at the middle layer. One millisecond instead of forty-five.
This pattern has a name: cache-aside, or read-through. Your app asks the cache, and on a miss it asks the database and writes the result back itself. The cache is not in the path of truth. It holds a copy, and copies go stale, so every key carries a TTL — that draining bar under the key. When it hits zero the key is gone and the next read pays full price again, which is exactly where the loop restarts.
Three things worth carrying out of this.
A miss costs more than a plain database read, not less. You pay the failed lookup, then the query, then the write. Adding a cache to something with no reuse makes it slower.
Your hit rate is a property of your traffic, not your cache. Same key read three times: two hits. Three different keys: three misses and a cold cache. The question was never how much memory you bought.
And a TTL is you choosing how wrong you're willing to be. Short means fresh and expensive. Long means fast and stale. There's no setting that gives you both.
Save this for your next system design interview.
#systemdesign #redis #caching #postgres #backend #softwareengineering #techinterview #systemdesigninterview #coding #programming
Use parameterized SQL queries to prevent injection attacks.
#postgres #sql #security
Two bookings hit the same two seats at the same second, and the database throws the one SQL error that means nobody’s code was wrong: deadlock detected.
This is how a database deadlock actually happens. Two correct transactions lock the same rows in opposite order, each ends up holding the seat the other needs, and everything freezes. Postgres and MySQL detect it and stop one transaction on purpose, but the stopped one won’t retry itself, your code has to catch the error and retry. The locking-order fix at the end turns the whole pileup into a queue.
If this error has hit you in production, what was your fix?
Sources:
Coffman, Elphick, Shoshani, “System Deadlocks” (ACM Computing Surveys, 1971)
PostgreSQL docs, Explicit Locking / deadlock detection
MySQL 8.0 Reference Manual, InnoDB deadlocks
#sql #postgres #mysql #deadlock #databases backend
Why did Instacart move search from Elasticsearch to Postgres? 🤔
It wasn’t because Elasticsearch was bad at search.
Instacart had a unique workload: billions of products, frequent inventory & price updates, and billions of writes every day.
Their denormalized Elasticsearch model created heavy indexing pressure. Moving search to normalized Postgres allowed them to:
* Reduce write workload by **10×**
* Use **GIN indexes + `ts_rank`** for full-text search
* Combine search, inventory, pricing, ML features & availability in one place
* Reduce network calls and overfetching
And the surprising part?
**Postgres ended up ~2× faster** for Instacart’s workload.
The lesson: the best technology isn’t always the most specialized one — it’s the one that fits your workload. 🚀
#faang #dsa #javascript #systemdesign #codinglife