Back-End Development Development 4 — Questions and Answers
Question 1: What is the difference between optimistic and pessimistic locking in databases?
- Optimistic locking prevents all concurrent reads; pessimistic locking allows them
- Optimistic locking assumes conflicts are rare and checks at commit time; pessimistic locking locks records upfront (Correct answer)
- Optimistic locking is used only in NoSQL; pessimistic locking only in SQL
- They are different names for the same mechanism
Correct answer: Optimistic locking assumes conflicts are rare and checks at commit time; pessimistic locking locks records upfront
Optimistic locking detects conflicts at commit time using version numbers, while pessimistic locking acquires locks immediately to prevent concurrent modification.
Question 2: Which HTTP/2 feature most improves performance over HTTP/1.1 for back-end APIs serving multiple resources?
- Persistent connections
- Multiplexing multiple streams over a single connection (Correct answer)
- Gzip compression support
- Cookie handling improvements
Correct answer: Multiplexing multiple streams over a single connection
HTTP/2 multiplexing allows multiple concurrent requests and responses over a single TCP connection, eliminating HTTP/1.1's head-of-line blocking.
Question 3: In a message queue system, what does 'dead letter queue' (DLQ) refer to?
- A queue for messages that have been successfully processed
- A special queue that receives messages that fail processing after maximum retries (Correct answer)
- A queue reserved for high-priority administrative messages
- A backup queue that mirrors the main queue
Correct answer: A special queue that receives messages that fail processing after maximum retries
A dead letter queue captures messages that cannot be processed successfully after repeated attempts, enabling debugging without losing the messages.
Question 4: What is N+1 query problem in ORM usage?
- Running one query to fetch a list, then one additional query per item to fetch related data (Correct answer)
- A query that returns N+1 rows more than expected due to a JOIN error
- Using N+1 database connections simultaneously
- Running the same query N+1 times due to a caching bug
Correct answer: Running one query to fetch a list, then one additional query per item to fetch related data
The N+1 problem occurs when fetching a list of N records triggers N additional queries to load their associations, which is solved by eager loading (e.g., JOIN or include).
Question 5: Which algorithm is commonly used for consistent hashing in distributed caching systems?
- MD5 hashing with linear probing
- SHA-256 with open addressing
- Ring-based consistent hashing (Correct answer)
- Round-robin with CRC32
Correct answer: Ring-based consistent hashing
Consistent hashing places nodes and keys on a virtual ring so that adding or removing nodes only remaps a minimal fraction of keys.
Question 6: In containerized back-end deployments, what is the primary function of a liveness probe in Kubernetes?
- To check if a container has enough CPU resources
- To determine whether a container should receive traffic
- To detect if a container is stuck and needs to be restarted (Correct answer)
- To measure response time SLAs for each pod
Correct answer: To detect if a container is stuck and needs to be restarted
A liveness probe tells Kubernetes whether a container is running correctly; if it fails, Kubernetes restarts the container to recover from deadlocks or fatal errors.
Question 7: What is the purpose of database sharding in large-scale back-end systems?
- To create encrypted backups of table data
- To horizontally partition data across multiple database instances to improve scalability (Correct answer)
- To compress table rows to reduce storage costs
- To replicate reads across multiple read replicas
Correct answer: To horizontally partition data across multiple database instances to improve scalability
Sharding splits a large dataset across multiple database nodes by a shard key, allowing write and read load to scale horizontally beyond a single machine's capacity.
What is the difference between optimistic and pessimistic locking in databases?