Skip to content
>_ StartupJobList_

Technology decisions

Redis vs PostgreSQL: cache and coordination beside durable data

Redis and PostgreSQL often complement each other. Put durable relational facts and invariants in PostgreSQL; use Redis for derived or ephemeral state when its freshness, eviction and recovery behavior is acceptable.

Decision guide for Redis and PostgreSQL as distinct data layers. Examples are illustrative and were not executed. Redis behavior depends on version/configuration; PostgreSQL behavior depends on version and isolation settings.

Redis and PostgreSQL serve different data roles in many systems: Redis offers key-oriented in-memory structures and coordination primitives, while PostgreSQL provides relational storage and transactions. They can coexist with explicit ownership, freshness and recovery boundaries.

Compare the practical consequences

Scroll sideways to compare all columns on a smaller screen.

Redis and PostgreSQL by decision criterion
CriterionRedisPostgreSQLWhat changes the decision
Data modelKey-oriented structures and bounded operations.Relational rows, joins and declarative constraints.Match each fact to the queries and invariants that own it.
FreshnessTTL/invalidation and cache-fill ordering define stale behavior.Committed transaction state is available to the configured isolation/read path.A cache must not authorize a final invariant-sensitive write.
Memory pressuremaxmemory policy may evict keys or reject writes.Storage growth and vacuum/index maintenance have different operational controls.Define which data may be lost and monitor the relevant capacity signals.
AtomicityCommand/script/transaction semantics are Redis-specific and do not roll back like SQL.SQL transactions and constraints cover relational invariants.Do not assume cross-system atomic commit; use outbox/reconciliation patterns.
RecoveryRDB/AOF, replication and restore configuration determine Redis recovery behavior.Backup, WAL and restore practice determine PostgreSQL recovery behavior.Exercise recovery; enabled persistence is not proof of a restore.
Best-fit pathShort-lived counters, cache projections and bounded coordination.Durable business facts, relational queries and multi-row integrity.These layers commonly coexist rather than replace one another.
Failure handlingOutage may cause cache misses, lost ephemeral state or write errors.Outage blocks authoritative reads/writes unless a separate recovery/read strategy exists.Bound fallback load and define user-visible degradation before launch.

↑ Back to sections

Are Redis and PostgreSQL substitutes?

Usually they serve different roles: PostgreSQL owns relational records and constraints; Redis can accelerate selected reads or coordinate bounded ephemeral state. Redis can be authoritative only when its recovery and data model fit the business contract.

PostgreSQL transactions, constraints and relational queries support durable multi-row invariants. Redis structures provide fast key-based operations and optional persistence, but persistence does not add relational constraints or joins. Define which system owns each fact before adding both.

Coexistence requires an explicit freshness and failure policy: what happens when Redis is empty, stale, unavailable or over memory? A cache is useful only when the source of truth can rebuild it safely.

Dataflow · Worked example
PostgreSQL owns product rows -> publish change event -> Redis stores derived view
Read: Redis hit or rebuild from PostgreSQL

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: When can Redis be the system of record?

When the workload fits its data model and the team has accepted and tested its persistence, recovery, replication, query and consistency properties.

Read the source: Redis data types · Redis persistence · PostgreSQL constraints

↑ Back to sections

How should cache-aside handle an update?

Commit the durable PostgreSQL write first, then invalidate or refresh the Redis entry with an idempotent event path. Define how stale fills are prevented or tolerated.

A delayed loader can fetch old PostgreSQL state, pause while a writer commits and deletes the cache, then repopulate Redis with stale data. Versioned entries or an outbox-driven update can make ordering explicit. A TTL bounds entry age only under its policy; it does not synchronize two systems.

If Redis is unavailable, decide whether the request can fall back to PostgreSQL and how to prevent a thundering herd. Rebuild only the derived key, not a competing source of truth.

SQL and worker trace · Worked example
BEGIN; UPDATE products SET price = $1 WHERE id = $2;
INSERT INTO outbox (...); COMMIT;
-- Worker applies versioned cache update idempotently.

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: What ordering race must a cache-fill path consider?

An old read can finish after an invalidation and write stale data back. Use versions/compare checks or an ordered event flow where freshness requires it.

Read the source: Redis cache-aside pattern · PostgreSQL transaction isolation

↑ Back to sections

When is Redis useful for counters or rate limits?

Redis can atomically update bounded counters and expire them; PostgreSQL should retain any audit or business event whose loss would violate the product requirement.

A fixed-window limiter can increment a bucket and set an expiry, but concurrent initialization and TTL behavior need deliberate commands or a short script. A distributed limiter also requires defining clock/window boundaries and what happens during Redis failover or eviction.

If the product must explain or dispute every rejection, persist enough durable event data separately. Do not assume the ephemeral aggregate is a complete ledger.

Redis CLI sketch · Worked example
INCR limit:user-7:minute-42
EXPIRE limit:user-7:minute-42 120
-- Use an atomic initialization/expiry protocol in real code.

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: How do you make counter creation atomic?

Use one command form or bounded script that initializes expiry on the first increment, and test it with concurrent calls and retry behavior.

Read the source: Redis data types · Redis transactions · PostgreSQL constraints

↑ Back to sections

Where should a reservation or financial invariant live?

Keep the invariant in PostgreSQL when it spans related durable records or needs relational constraints and transactional history. Redis may cache availability but should not silently become the only authority.

A booking needs conflict handling and a durable result. PostgreSQL can use a unique/exclusion constraint or transaction strategy; Redis can accelerate a read path, but stale availability must not authorize the final booking.

If Redis itself is selected as the primary store for a specific use case, define its persistence, replication, eviction and recovery assumptions explicitly. “It has AOF” is not a substitute for an exercised recovery plan.

Request trace · Worked example
read availability from cache -> attempt authoritative PostgreSQL reservation
if conflict: invalidate derived availability and return conflict

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: How do you handle cache disagreement after commit?

Treat the committed database result as truth, invalidate/update the derived view idempotently, and reconcile missed events from a durable outbox or change log.

Read the source: PostgreSQL constraints · PostgreSQL transaction isolation · Redis persistence

↑ Back to sections

What happens if Redis disappears?

A cache-only Redis outage should degrade to the durable source with bounded load, or return a clear temporary error if that source cannot absorb the traffic. Recovery requires safe repopulation.

A cold cache can create a stampede against PostgreSQL. Use coalescing, bounded stale data or rate limits only when they preserve the product contract. For a Redis authoritative dataset, restore from the actual configured persistence and replication recovery process.

Test the outage and restore path in isolation; replication can copy bad writes and does not equal an independent backup.

Failure-mode trace · Worked example
Redis timeout -> bounded PostgreSQL fallback -> rate-limited cache rebuild
Redis primary -> tested restore/failover process

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: What should a recovery exercise report?

Data loss window, recovery time, integrity checks, stale-cache behavior and the maximum fallback load the durable store can sustain.

Read the source: Redis persistence · PostgreSQL backup and restore · Redis cache-aside pattern

↑ Back to sections

Scenario: product catalog reads are frequent and edits are moderate

Use PostgreSQL as the product record store and cache a selected read projection in Redis if measurement shows the cache helps. Make invalidation and stale-read tolerance explicit.

The reader can tolerate a short stale window for a product description but may require current price at checkout. Cache those fields under different policies or revalidate the price in the transaction that creates the order.

Reverse the cache choice if hit rate is low, invalidation complexity exceeds the saved work, or PostgreSQL already meets the measured latency and load target.

Workload scenario · Worked example
catalog read -> Redis projection (short TTL)
checkout -> PostgreSQL transaction rechecks price and inventory

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: What should be measured?

End-to-end latency, origin load, cache hit/miss, stale response rate and behavior during invalidation/outage, all under representative traffic.

Read the source: Redis cache-aside pattern · PostgreSQL transaction isolation

↑ Back to sections

Scenario: an API needs a distributed per-account rate limit

Use Redis for short-lived counters when requests may land on multiple app instances, and persist business audit data separately if needed. Pick window and outage behavior explicitly.

An atomic counter and TTL can enforce a simple fixed window. A rolling window, fairness guarantee or abuse investigation may require a different algorithm and durable records. Redis eviction and failover can reset or lose limiter state, so decide whether to fail open, fail closed or use a fallback.

PostgreSQL can store audit events, but writing every request there has different throughput and retention costs. Choose from the product’s enforcement and audit requirements, not a generic “Redis is faster” claim.

Request-flow scenario · Worked example
request -> atomic Redis bucket check -> allow/deny
accepted business event -> PostgreSQL audit/outbox

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: When would PostgreSQL alone be enough?

When the rate is low, the policy is naturally transactional with existing records, or a simpler durable implementation meets the measured load and latency.

Read the source: Redis data types · Redis eviction · PostgreSQL constraints

↑ Back to sections

How do you move an existing Redis-only record set to PostgreSQL?

Define the canonical record and cutover invariant first. Backfill, reconcile and switch reads/writes in stages; dual writes need a durable repair path.

A safe plan identifies key types, TTL meaning, serialization versions, duplicate identities and data whose expiry indicates it is not a durable business record. Capture a consistent migration boundary, backfill in bounded batches, compare counts/checksums and reconcile writes before cutover.

Keep Redis as a derived cache only after PostgreSQL is authoritative and rebuild behavior works. Rollback needs a compatible path; never infer that every Redis key should become a relational row.

Migration sketch · Worked example
inventory Redis keys -> classify transient vs durable
backfill durable subset -> compare -> route writes -> reconcile -> cut over

Illustrative dataflow or command; not executed.

Illustrative, not executed.

Follow-up: What reverses the cutover?

Mismatch in canonical data, unacceptable write lag, failed restore/reconciliation, or evidence that the target schema cannot preserve required semantics.

Read the source: Redis persistence · Redis data types · PostgreSQL constraints

↑ Back to sections

Salary context

Advertised salaries for these skills

These are Hacker News job posts that mention these technologies, not employee earnings or a measure of what a skill adds to pay. The amounts summarize annualized advertised minimums in approximate USD. Groups can overlap and differ in roles, locations and dates.

Redis posts

45 posts · 45 usable advertised salary amounts

2024-09-04 to 2026-11-02

$142,723

Median advertised minimum, approximate USD/year

Middle 50%: $89,376–$165,000

Explore Redis salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged Redis, rather than every job in the broader technology family.

PostgreSQL posts

329 posts · 329 usable advertised salary amounts

2024-06-04 to 2026-11-06

$140,000

Median advertised minimum, approximate USD/year

Middle 50%: $113,891–$170,000

Explore PostgreSQL salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged PostgreSQL, rather than every job in the broader technology family.

Middle-half salary ranges on one shared scale

The band runs from the 25th to 75th percentile; the vertical marker is the median. Both rows use approximate USD per year.

Redis $142,723 median
PostgreSQL $140,000 median
$89,376$170,000

31 posts mention both technologies. That is 68.9% of Redis posts and 9.4% of PostgreSQL posts. A post can belong to both groups. This overlap does not show that employers prefer one technology, and the two salary groups are not independent samples.

↑ Back to sections

Keep exploring