Design Patterns · Middle · Question 6 of 75

What's dangerous about a module-level singleton (export const cache = new Map()) in an SSR app?

Explanation

In the browser, a module variable lives within one tab. A server process serves thousands of users, and a shared module-level cache or store can serve one user's data to another. Request state is created per request (e.g. React's cache(), a QueryClient per request).

Further reading

Problem with a question

Design Patterns · Middle · question 6

Test yourself

Take the Design Patterns · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz