How a 65ms Redis GET, a regional mismatch, and some k6 load testing taught me an important lesson about caching.

Introduction

When building applications, one of the most common performance recommendations you'll hear is:

"Add Redis caching to reduce database queries and improve performance."

Naturally, I wanted to implement this in my URL shortener.

My architecture was relatively simple:

  • Frontend: Vercel

  • Backend: Node.js(Express) on Render

  • Database: PostgreSQL on Neon

  • Cache: Redis on Upstash

The idea was straightforward.

Whenever someone visits a shortened URL, the backend checks Redis first. If the URL is cached, it redirects immediately. Otherwise, it queries PostgreSQL, retrieves the original URL, caches it in Redis, and redirects.

Everything seemed correct.

But when I started benchmarking, I encountered something unexpected.

My application was significantly slower with Redis enabled than without it.

This is how I investigated the problem and what I learned.

1. Implementing Redis caching

I implemented a simple cache-aside strategy.

The redirect flow looked like this:

  1. Receive a request containing the shortened URL.
  2. Check Redis for the original URL.
  3. If there's a cache hit, redirect immediately.
  4. If there's a cache miss, query PostgreSQL.
  5. Store the result in Redis.
  6. Redirect to the original URL.

My redirect handler looked something like this:

router.get('/:encodedUrl', async (req, res) => { try { const { encodedUrl } = req.params; if (CACHE_ENABLED) { const cachedUrl = await getCachedUrl(encodedUrl); if (cachedUrl) { console.log('CACHE HIT:', encodedUrl); return res.redirect(302, cachedUrl); } console.log('CACHE MISS:', encodedUrl); } const record = await db.orm.public.Link .where({ shortCode: encodedUrl }) .first(); if (!record) { return res.status(404).json('URL not found'); } if (CACHE_ENABLED) { void setCachedUrl(encodedUrl, record.longUrl); } return res.redirect(302, record.longUrl); } catch (error) { console.error('Redirect error:', error); return res.status(500).json('Internal server error'); } }); 

The Redis helper used the official Node Redis client:

import { createClient } from 'redis'; const redisClient = createClient({ url: process.env.REDIS_URL, disableOfflineQueue: true }); export const getCachedUrl = async (code: string) => { try { return await redisClient.get(code); } catch (error) { console.error('Redis GET Error:', error); return null; } }; export const setCachedUrl = async ( code: string, longUrl: string ) => { try { await redisClient.setEx(code, 3600, longUrl); } catch (error) { console.error('Redis SET Error:', error); } }; 

The implementation looked correct. Cache hits were being logged, and the database query was skipped on cache hits.

So why was Redis making things slower?

2. My first load test: Redis made everything slower

I used k6 to benchmark the redirect endpoint.

For both tests, I used the same shortened URL, the same load-testing script, and the same deployment.

The initial test used up to 10 virtual users.

Without Redis

+-----------------+-----------+ | Metric | Result | +-----------------+-----------+ | Average latency | 87 ms | | Median latency | 78.6 ms | | p95 latency | 124.84 ms | | Throughput | 66.58 req/s| | Failed requests | 0% | +-----------------+-----------+ 

With Redis

+-----------------+-----------+ | Metric | Result | +-----------------+-----------+ | Average latency | 139.06 ms | | Median latency | 136.13 ms | | p95 latency | 150.27 ms | | Throughput | 41.66 req/s| | Failed requests | 0% | +-----------------+-----------+ 

This was confusing.

Redis was supposed to make the application faster, but:

Average latency increased by approximately 60%.
Throughput decreased by approximately 37%.
And the interesting part?

I was getting cache hits!

My first assumption was that something was wrong with my caching implementation.

But I decided to investigate before changing the code.

3. Measuring Redis latency independently

Instead of looking only at the overall HTTP response time, I added timing instrumentation around the Redis GET operation.

const start = performance.now(); const cachedUrl = await getCachedUrl(encodedUrl); console.log( 'Redis GET:', (performance.now() - start).toFixed(2), 'ms' ); 

The result was surprising.

Redis GET was taking approximately 64–65 ms.
I also measured Redis PING:

export const testRedisPing = async () => { const start = performance.now(); await redisClient.ping(); console.log( 'Redis PING:', (performance.now() - start).toFixed(2), 'ms' ); }; 

The PING operation was also taking approximately 62 ms.

This gave me an important clue.

The problem probably wasn't Redis retrieving the key. The time was being spent communicating with the Redis server.

4. The actual problem: Deployment regions

I checked the deployment regions of my services.

And there it was.

+-----------------------+-----------+ | Service | Region | +-----------------------+-----------+ | Render (Express backend) | Singapore | | Neon (PostgreSQL) | Singapore | | Upstash (Redis) | Mumbai | +-----------------------+-----------+ 

My backend and PostgreSQL database were in Singapore, but Redis was in Mumbai.

Every cache hit required a network round trip between Singapore and Mumbai.

Meanwhile, my database was in the same region as my backend.

I had overlooked something important:

A fast database or cache can still produce slow application performance if the network path to that service is expensive.

Redis was doing its job. My infrastructure placement was the problem.

5. The fix: Moving Redis to Singapore

I changed the Upstash Redis database region from Mumbai to Singapore.

I didn't change:

  • My redirect handler.
  • My Redis caching strategy.
  • My Node Redis client.
  • My database queries.

I simply aligned the Redis deployment region with my backend and database.

Then I measured Redis latency again.

+-------------+----------+---------+ | Metric | Before | After | +-------------+----------+---------+ | Redis PING | 62.20 ms | 1.50 ms | | Redis GET | 64-65 ms | 1.56 ms | +-------------+----------+---------+ 

That's approximately a 97.6% reduction in Redis GET latency.

A relatively simple infrastructure change made a massive difference.

6. Testing again with k6

With Redis now deployed in Singapore, I repeated the original benchmark.

At 10 virtual users

+-----------------+-----------+-----------+ | Metric | Redis OFF | Redis ON | +-----------------+-----------+-----------+ | Average latency | 81.91 ms | 81.52 ms | | Throughput | 70.77 req/s| 71.01 req/s| | p95 latency | 95.89 ms | 105.25 ms | | Failed requests | 0% | 0% | +-----------------+-----------+-----------+ 

At this concurrency level, both configurations performed almost identically.

This was another interesting observation.

Redis wasn't providing a significant throughput advantage at low concurrency because PostgreSQL was already handling the workload comfortably.

I decided to increase the load.

At 100 virtual users

+-----------------+------------+------------+ | Metric | Redis OFF | Redis ON | +-----------------+------------+------------+ | Throughput | 140.99 req/s| 259.85 req/s| | Average latency | 286.13 ms | 154.64 ms | | Median latency | 204.53 ms | 105.87 ms | | p95 latency | 712.29 ms | 300.29 ms | | Failed requests | 0% | 0% | +-----------------+------------+------------+ 

Redis provided:

  • 84.3% higher throughput.
  • 46% lower average latency.
  • 57.9% lower p95 latency.

The difference was becoming much more noticeable.

At 200 virtual users

This was the most interesting test.

+-----------------+--------------+------------+ | Metric | Redis OFF | Redis ON | +-----------------+--------------+------------+ | Throughput | 156.67 req/s | 309.83 req/s| | Average latency | 716.67 ms | 360.59 ms | | Median latency | 706.89 ms | 386.27 ms | | p90 latency | 1,200 ms | 596.57 ms | | p95 latency | 1,400 ms | 607.70 ms | | Maximum latency | 1.99 s | 1.52 s | | Failed requests | 0% | 0% | +-----------------+--------------+------------+ 

The improvement was substantial.

With Redis enabled:

  • Throughput increased by approximately 97.7%.
  • Average latency decreased by approximately 49.7%.
  • p95 latency decreased by approximately 56.6%.
  • Almost twice as many requests were completed during the test.

The application handled approximately 310 requests per second with Redis, compared to approximately 157 requests per second without it.

7. What I learned

This experiment taught me a few things that I hadn't fully appreciated before implementing Redis.

1. Caching doesn't automatically make applications faster

Adding Redis introduces another network dependency.

If the cache server is geographically far from your backend, the network latency can outweigh the time saved by avoiding a database query.

2. Infrastructure region placement matters

Your backend, database, and cache should ideally be deployed in geographically close regions.

Even when two services are in the same city, their network paths and hosting infrastructure can affect latency.

3. Measure individual operations, not just overall response times

Initially, I was only looking at k6's HTTP response times.

Measuring Redis GET and PING independently helped me identify the actual bottleneck.

Without those measurements, I might have unnecessarily rewritten my caching implementation.

4. Redis becomes more valuable under higher concurrency

At 10 VUs, Redis made almost no measurable difference.

At 100 and 200 VUs, the throughput and latency improvements became substantial.

The benefits of caching depend on the workload, database performance, cache hit ratio, and available infrastructure resources.

5. Always benchmark instead of assuming

I initially expected Redis to make everything faster.

Instead, it made the application slower.

Only after measuring, investigating, and correcting the deployment regions did I see the expected benefits.

Conclusion

This was a useful lesson in understanding that application performance isn't just about choosing fast technologies.

It's also about how those technologies communicate with each other.

Redis wasn't the problem. My caching implementation wasn't the problem. The deployment architecture was.

The biggest takeaway for me:

Before optimizing your code, understand the network paths your application depends on.

Sometimes the biggest performance improvement doesn't come from writing better code. It comes from deploying your existing code in the right places.

_Tech stack: Node.js, Express.js, PostgreSQL, Redis, Upstash, Neon, Vercel, Render, k6.

All benchmarks were performed on my deployed free-tier infrastructure. Results represent my particular test environment and should not be interpreted as universal performance guarantees._