POC Architecture & System Design 3 — Questions and Answers
Question 1: Which Python pattern separates the construction of a complex object from its representation?
- Strategy
- Builder (Correct answer)
- Proxy
- Flyweight
Correct answer: Builder
The Builder pattern uses a director and builder classes to construct complex objects step-by-step, separating construction logic from the final representation.
Question 2: In a Python application using the Repository pattern, what is the primary responsibility of the repository class?
- To define business rules for domain entities
- To abstract data access and provide collection-like interfaces for domain objects (Correct answer)
- To orchestrate multiple service calls in a transaction
- To serialize objects to JSON for API responses
Correct answer: To abstract data access and provide collection-like interfaces for domain objects
The Repository pattern abstracts the data layer, providing a clean interface for accessing domain objects without exposing database implementation details.
Question 3: Which Python architectural approach best supports the principle of 'separation of concerns' in a web application?
- Putting all logic in view functions
- Model-View-Controller (MVC) or Model-View-Template (MVT) (Correct answer)
- Using a single large module for all application code
- Embedding SQL directly in template files
Correct answer: Model-View-Controller (MVC) or Model-View-Template (MVT)
MVC/MVT separates data models, presentation logic, and business/control logic into distinct layers, keeping concerns isolated and maintainable.
Question 4: What is the main advantage of using Python's `asyncio` event loop in a high-concurrency system design?
- It automatically distributes work across CPU cores
- It handles thousands of concurrent I/O-bound operations without blocking threads (Correct answer)
- It provides automatic garbage collection for large objects
- It replaces the need for a database connection pool
Correct answer: It handles thousands of concurrent I/O-bound operations without blocking threads
asyncio uses cooperative multitasking to handle many I/O-bound operations concurrently on a single thread without thread overhead.
Question 5: In a Python service using the Command pattern, what does the 'invoker' component do?
- Implements the actual business logic for each command
- Stores the history of executed commands for undo support
- Triggers command execution without knowing the concrete command details (Correct answer)
- Translates between different command formats
Correct answer: Triggers command execution without knowing the concrete command details
The invoker holds a reference to a command object and triggers its execute() method, decoupling the caller from the receiver of the action.
Question 6: What problem does the Circuit Breaker pattern solve in a Python microservices system?
- Preventing SQL injection in service-to-service calls
- Stopping cascading failures when a downstream service is unavailable (Correct answer)
- Balancing load evenly across service replicas
- Encrypting inter-service communication automatically
Correct answer: Stopping cascading failures when a downstream service is unavailable
The Circuit Breaker pattern trips open when a service fails repeatedly, preventing the calling service from wasting resources on doomed requests and allowing time for recovery.
Question 7: Which Python data structure is best suited as a backing store for implementing an LRU (Least Recently Used) cache from scratch?
- list
- set
- collections.OrderedDict (Correct answer)
- tuple
Correct answer: collections.OrderedDict
collections.OrderedDict maintains insertion order and supports move_to_end(), making it efficient for LRU eviction without additional linked list logic.
Which Python pattern separates the construction of a complex object from its representation?