Questions
1 of 1
01 / 01

What is memoisation?

Memoization is an optimization technique used to store the results of expensive function calls and return the cached result when the same inputs occur again. It can greatly improve the performance of functions that are repeatedly called with the same arguments.

javascript
Difficulty: 5/10
Topics: caching, pure functions, performance

Scenario Questions

0-2 years experience
  1. 1

    We have a recursive function that calculates the nth Fibonacci number. How would you add memoisation in JavaScript to make it run faster?

  2. 2

    If you call a memoised function twice with the same arguments, what does it return and why?

  3. 3

    What could happen to memory usage if a memoised cache never gets cleared in a single‑page app?

2-5 years experience
  1. 1

    You memoised a data‑fetching helper that caches results by query parameters. After release, some users see stale data when the backend updates. Why might that happen and how would you fix it?

  2. 2

    A teammate says memoising a pure utility function caused a memory leak in a long‑running Node service. How would you investigate and resolve the issue?

  3. 3

    What are the trade‑offs between using a plain object versus a WeakMap for memoisation inside a React component?

5-8 years experience
  1. 1

    Design a memoisation layer for a high‑traffic API gateway that must cache expensive calculation results across multiple instances. What consistency, eviction, and scaling concerns would you address?

  2. 2

    Our microservice memoises functions that depend on user‑specific context. How do you prevent the cache from leaking across users while still getting reuse benefits?

  3. 3

    If we need to invalidate memoised results based on external events like a config change, what pattern would you implement in JavaScript to propagate invalidation safely?

8+ years experience
  1. 1

    We are moving a legacy monolith that heavily relies on in‑process memoisation to a serverless architecture. How would you refactor or replace that approach so it works across stateless Lambda invocations?

  2. 2

    Several teams use memoisation inconsistently, leading to hidden bugs and performance regressions. As a staff engineer, how would you establish guidelines, tooling, and monitoring to manage memoisation organization‑wide?

  3. 3

    When deciding between client‑side memoisation, edge CDN caching, and server‑side caching, what factors guide your choice and how would you communicate the trade‑offs to product and ops?

Follow-up Questions

  • Can you walk me through how you'd implement the cache in code?
  • What edge cases or bugs might arise with this approach?
  • How would you measure the performance impact after adding memoisation?