DEV Community

Ateeb Hussain
Ateeb Hussain

Posted on

Using Next.js with Redis

Is Redis (Upstash Redis) with Next.js a good matchup?

Another week of developing ECourses, an LMS SaaS (also opensource)

I implemented caching, or more precisely redis cache for the first time.

So... the previous was sending 10 database read queries while creating a single course.
What is that? Probably because I was fetching instructors to assign to a course and then for filtering too.

At first, I was using TanStack React Query for caching until it hit me that the cache is session based and temporary.

SSR or ISR are a bit headache because form is on client-side code.

So, it was time add some caching layers.
I already had React Query cache implemented, what need was redis to store recent data from database and next.js cache to store requested data for a short period of time – or until invalidated

The current caching flow looks like this:
User --> React Query --> NextJS Cache --> Redis Cache --> Database (PostgreSQL)

So, what are your thoughts about this flow...? I don't have a large group of users but I want to stay under the free stack, and hashtag#prisma postgres provides 10 concurrent connections with 100,000 operations per month.

P.S. What was your first caching flow you created?

Top comments (0)