Back-End Development Back-End Performance and Caching 2 — Questions and Answers
Question 1: What is a cache eviction policy and what does LRU stand for?
- A backup rotation policy — Least Recently Used
- The strategy for removing cached items when the cache is full — Least Recently Used means removing the item accessed least recently (Correct answer)
- A database archiving policy — Large Record Utility
- A network routing algorithm — Load Redistribution Unit
Correct answer: The strategy for removing cached items when the cache is full — Least Recently Used means removing the item accessed least recently
Cache eviction policies determine which items to remove when the cache reaches capacity; LRU (Least Recently Used) evicts the item that hasn't been accessed for the longest time.
Question 2: What is the thundering herd problem in caching?
- Many servers crashing simultaneously under high load
- A situation where many requests simultaneously hit the origin/database when a popular cached item expires (Correct answer)
- A network failure caused by too many connected clients
- A memory leak caused by indefinitely growing cache size
Correct answer: A situation where many requests simultaneously hit the origin/database when a popular cached item expires
The thundering herd occurs when a highly-requested cached item expires simultaneously for all callers, causing a surge of requests to hit the database at once before the cache is repopulated.
Question 3: What is HTTP caching and which header controls cache duration for browser and CDN caching?
- Server-side query caching — controlled by the X-Cache-Control header
- Browser and CDN caching of HTTP responses — controlled by the Cache-Control header (Correct answer)
- Application-level memory caching — controlled by the Expires header only
- Database result caching — controlled by the Pragma header
Correct answer: Browser and CDN caching of HTTP responses — controlled by the Cache-Control header
The Cache-Control header (e.g., max-age=3600, public) instructs browsers and CDNs how long to cache a response, reducing server load and improving client-perceived performance.
Question 4: What is the purpose of database query optimization techniques like selecting only needed columns?
- To reduce the number of tables in the database
- To minimize the amount of data transferred from the database, reducing memory use and network overhead (Correct answer)
- To prevent SQL injection attacks
- To ensure queries use the correct data types
Correct answer: To minimize the amount of data transferred from the database, reducing memory use and network overhead
Using SELECT column1, column2 instead of SELECT * limits data retrieval to only needed fields, reducing memory consumption, network bandwidth, and the chance of exposing sensitive columns.
Question 5: What is async/await and why is it important for back-end I/O performance in Node.js?
- A syntax for writing synchronous code in a more readable way without any performance benefit
- Syntax sugar over Promises that allows non-blocking I/O operations, keeping the event loop free to handle other requests while waiting (Correct answer)
- A multi-threading mechanism for parallel CPU computation in Node.js
- A framework for managing background worker processes
Correct answer: Syntax sugar over Promises that allows non-blocking I/O operations, keeping the event loop free to handle other requests while waiting
async/await enables writing asynchronous code that reads like synchronous code while keeping Node.js's single-threaded event loop free during I/O waits, allowing the server to handle thousands of concurrent requests efficiently.
Question 6: What is memoization in the context of back-end performance?
- Storing application logs in memory for faster retrieval
- An optimization technique that caches the results of expensive function calls and returns the cached result for the same inputs (Correct answer)
- Loading application configuration into memory at startup
- A technique for reducing memory usage by compressing data structures
Correct answer: An optimization technique that caches the results of expensive function calls and returns the cached result for the same inputs
Memoization caches a function's return value keyed by its input arguments, so subsequent calls with the same inputs return the cached result instantly without re-executing the function.
What is a cache eviction policy and what does LRU stand for?