Back-End Development Back-End Performance and Caching 1 — Questions and Answers
Question 1: What is Redis and what is it commonly used for in back-end applications?
- A relational database for storing structured data
- An in-memory data store used for caching, session management, real-time leaderboards, and message brokering (Correct answer)
- A front-end state management library
- A cloud object storage service
Correct answer: An in-memory data store used for caching, session management, real-time leaderboards, and message brokering
Redis is an in-memory key-value store with data structures like strings, hashes, lists, and sets, widely used to cache expensive computations, store sessions, and power real-time features.
Question 2: What is the difference between CPU-bound and I/O-bound operations in back-end applications?
- CPU-bound operations wait for network or disk; I/O-bound operations require heavy computation
- CPU-bound operations are limited by processing power; I/O-bound operations are limited by waiting for external resources like disk or network (Correct answer)
- CPU-bound operations run on the server; I/O-bound operations run on the client
- There is no meaningful difference in back-end performance tuning
Correct answer: CPU-bound operations are limited by processing power; I/O-bound operations are limited by waiting for external resources like disk or network
CPU-bound tasks (encryption, image processing) are bottlenecked by processor speed, while I/O-bound tasks (database queries, file reads) spend most time waiting for external systems.
Question 3: What is lazy loading in the context of back-end data retrieval?
- Loading all data at startup to avoid delays later
- Deferring the loading of data until it is actually needed, reducing initial load time and memory usage (Correct answer)
- Caching data indefinitely to avoid repeated database queries
- Loading data in alphabetical order for efficiency
Correct answer: Deferring the loading of data until it is actually needed, reducing initial load time and memory usage
Lazy loading delays fetching related data until it is explicitly accessed, avoiding unnecessary database queries and reducing memory consumption for data that may never be needed.
Question 4: What does TTL (Time to Live) mean in the context of caching?
- The total time a server has been running
- The duration after which a cached item expires and must be refreshed from the source (Correct answer)
- The maximum time a database query is allowed to run
- The time limit for an API request to complete
Correct answer: The duration after which a cached item expires and must be refreshed from the source
TTL defines how long a cached value remains valid before it is considered stale and must be re-fetched or recomputed from the original data source.
Question 5: What is content compression and which algorithm is most commonly used for HTTP responses?
- Resizing images for mobile devices — JPEG compression
- Reducing the size of HTTP response bodies — Gzip or Brotli compression (Correct answer)
- Encrypting response payloads — AES compression
- Minifying JavaScript files — UglifyJS compression
Correct answer: Reducing the size of HTTP response bodies — Gzip or Brotli compression
Gzip and Brotli compress HTTP response bodies (HTML, JSON, JS, CSS) before transmission, often reducing payload size by 60-80% and significantly improving transfer speeds.
Question 6: What is the purpose of a worker process or background job in a back-end application?
- To replace the main web server process for heavy traffic
- To handle time-consuming tasks (email sending, image processing, report generation) asynchronously outside the request-response cycle (Correct answer)
- To monitor the health of the web server process
- To synchronize database replicas in real time
Correct answer: To handle time-consuming tasks (email sending, image processing, report generation) asynchronously outside the request-response cycle
Background workers process long-running tasks from a queue (like Bull, Sidekiq, or Celery) asynchronously, allowing the web server to respond to the client immediately without blocking.
What is Redis and what is it commonly used for in back-end applications?