Full-Stack Development Technology & Digital Applications 4 — Questions and Answers
Question 1: Which caching strategy serves a cached response immediately and then updates the cache in the background from the network?
- Cache-first
- Network-first
- Stale-while-revalidate (Correct answer)
- Cache-only
Correct answer: Stale-while-revalidate
Stale-while-revalidate returns the cached (potentially stale) response instantly while simultaneously fetching a fresh version for the next request.
Question 2: In React, what is the purpose of the `key` prop when rendering lists?
- It applies a CSS class to each list item
- It helps React identify which items changed, were added, or removed to optimize reconciliation (Correct answer)
- It prevents duplicate values in the list
- It sets the accessible label for screen readers
Correct answer: It helps React identify which items changed, were added, or removed to optimize reconciliation
React uses the `key` prop to match elements between renders, avoiding unnecessary re-creation of DOM nodes when the list changes.
Question 3: What does the CAP theorem state about distributed databases?
- A system can simultaneously guarantee consistency, availability, and partition tolerance
- A distributed system can guarantee at most two of: consistency, availability, and partition tolerance (Correct answer)
- Partition tolerance is optional if both consistency and availability are needed
- The theorem applies only to SQL databases, not NoSQL
Correct answer: A distributed system can guarantee at most two of: consistency, availability, and partition tolerance
CAP theorem (Brewer's theorem) proves that a distributed data store can only guarantee two of the three properties when a network partition occurs.
Question 4: Which HTTP method is idempotent but NOT safe (it may modify server state)?
- GET
- HEAD
- PUT (Correct answer)
- OPTIONS
Correct answer: PUT
PUT is idempotent (calling it multiple times produces the same result) but not safe because it modifies or creates a resource on the server.
Question 5: In a single-page application (SPA), what problem does code splitting solve?
- It splits CSS from JavaScript to reduce selector conflicts
- It divides the bundle into smaller chunks loaded on demand, reducing initial load time (Correct answer)
- It separates frontend code from backend code into distinct repositories
- It prevents multiple browser tabs from loading the same script
Correct answer: It divides the bundle into smaller chunks loaded on demand, reducing initial load time
Code splitting allows the bundler to create multiple smaller bundles that load lazily when needed, improving Time to Interactive for large applications.
Question 6: What is the role of an API gateway in a microservices architecture?
- It compiles microservice code into a single deployable binary
- It acts as a single entry point that routes requests, handles auth, rate limiting, and cross-cutting concerns (Correct answer)
- It stores shared configuration values for all microservices
- It replaces the need for load balancers
Correct answer: It acts as a single entry point that routes requests, handles auth, rate limiting, and cross-cutting concerns
An API gateway sits in front of all microservices, providing a unified interface while handling cross-cutting concerns like authentication, logging, and rate limiting.
Question 7: Which technique prevents SQL injection attacks in web applications?
- Validating that user input contains only uppercase letters
- Using parameterized queries (prepared statements) to separate SQL code from user data (Correct answer)
- Encrypting all database columns with AES-256
- Limiting database users to read-only access
Correct answer: Using parameterized queries (prepared statements) to separate SQL code from user data
Parameterized queries bind user input as data rather than executable SQL, so malicious strings cannot alter the query's structure.
Which caching strategy serves a cached response immediately and then updates the cache in the background from the network?