Back-End Development Development 3 — Questions and Answers
Question 1: In Node.js, what mechanism allows non-blocking I/O operations despite JavaScript being single-threaded?
- Multi-threading via worker_threads only
- The event loop and libuv async I/O library (Correct answer)
- Shared memory across V8 instances
- Operating system process forking on every request
Correct answer: The event loop and libuv async I/O library
Node.js delegates I/O to libuv, which uses OS-level async mechanisms, and the event loop picks up callbacks when operations complete.
Question 2: What SQL clause is used to filter groups produced by GROUP BY?
- WHERE
- HAVING (Correct answer)
- FILTER
- LIMIT
Correct answer: HAVING
HAVING filters aggregated groups after GROUP BY, whereas WHERE filters rows before aggregation.
Question 3: Which caching strategy writes data to the cache and the database simultaneously on every write?
- Cache-aside
- Write-through (Correct answer)
- Write-behind
- Read-through
Correct answer: Write-through
Write-through ensures the cache and database are always in sync by writing to both on every update, at the cost of higher write latency.
Question 4: What does CORS stand for, and why do browsers enforce it?
- Cross-Origin Resource Sharing; browsers enforce it to prevent unauthorized cross-origin requests (Correct answer)
- Cached Object Request System; browsers enforce it to speed up repeated requests
- Cross-Origin Routing Schema; browsers use it to select the fastest server
- Content Object Rendering Standard; browsers enforce it for accessibility
Correct answer: Cross-Origin Resource Sharing; browsers enforce it to prevent unauthorized cross-origin requests
CORS is a security mechanism that restricts web pages from making requests to a different origin than the one that served the page.
Question 5: Which index type is most efficient for equality lookups on low-cardinality columns in a relational database?
- B-tree index
- Full-text index
- Bitmap index (Correct answer)
- Hash index
Correct answer: Bitmap index
Bitmap indexes are highly efficient for low-cardinality columns (e.g., gender, status) because they represent values as bit arrays enabling fast bitwise operations.
Question 6: In OAuth 2.0, what is the purpose of the refresh token?
- To authenticate the user without a password
- To obtain a new access token when the current one expires (Correct answer)
- To encrypt the authorization code
- To revoke all existing sessions for a user
Correct answer: To obtain a new access token when the current one expires
Refresh tokens allow clients to obtain new access tokens without requiring the user to re-authenticate, extending session longevity securely.
Question 7: Which design principle states that a class should have only one reason to change?
- Open/Closed Principle
- Liskov Substitution Principle
- Single Responsibility Principle (Correct answer)
- Interface Segregation Principle
Correct answer: Single Responsibility Principle
The Single Responsibility Principle (SRP) dictates that a class should encapsulate only one concern so that changes to one requirement affect only one class.
In Node.js, what mechanism allows non-blocking I/O operations despite JavaScript being single-threaded?