POC Architecture & System Design 2 — Questions and Answers
Question 1: Which Python design pattern ensures a class has only one instance and provides a global access point to it?
- Factory
- Singleton (Correct answer)
- Observer
- Decorator
Correct answer: Singleton
The Singleton pattern restricts instantiation to one object by controlling the class's __new__ or __init__ method.
Question 2: In a Python microservices architecture, what is the primary purpose of an API Gateway?
- To store shared session data across services
- To serve as a single entry point routing requests to backend services (Correct answer)
- To replicate database changes across services
- To compile Python bytecode on the fly
Correct answer: To serve as a single entry point routing requests to backend services
An API Gateway acts as a reverse proxy that routes client requests to appropriate microservices and can handle cross-cutting concerns like auth and rate limiting.
Question 3: Which Python library is commonly used to implement asynchronous task queues in a distributed system?
- Flask
- Celery (Correct answer)
- SQLAlchemy
- Pydantic
Correct answer: Celery
Celery is a distributed task queue library for Python that enables offloading work to background workers using brokers like Redis or RabbitMQ.
Question 4: What does the acronym SOLID stand for in object-oriented design as applied to Python?
- Single, Open, Liskov, Interface, Dependency (Correct answer)
- Simple, Object, Logic, Inheritance, Design
- Structured, Ordered, Linked, Integrated, Dynamic
- Static, Oriented, Layered, Integrated, Directed
Correct answer: Single, Open, Liskov, Interface, Dependency
SOLID stands for Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion principles.
Question 5: When designing a Python system that must handle millions of events per second, which architecture pattern is most appropriate?
- Monolithic with multi-threading
- Event-driven architecture with message streaming (Correct answer)
- Synchronous REST with connection pooling
- Batch processing with cron jobs
Correct answer: Event-driven architecture with message streaming
Event-driven architecture with message streaming (e.g., Kafka) decouples producers and consumers, enabling high-throughput real-time processing.
Question 6: In Python, which module provides the abstract base class infrastructure used to enforce interface contracts?
- abc (Correct answer)
- typing
- inspect
- functools
Correct answer: abc
The `abc` module provides the ABCMeta metaclass and @abstractmethod decorator to define and enforce abstract interfaces in Python.
Question 7: What is the key difference between horizontal and vertical scaling in a Python web application context?
- Horizontal adds more powerful hardware; vertical adds more servers
- Horizontal adds more servers; vertical adds more resources to existing servers (Correct answer)
- Horizontal uses threads; vertical uses processes
- Horizontal scales the database; vertical scales the application
Correct answer: Horizontal adds more servers; vertical adds more resources to existing servers
Horizontal scaling (scale out) adds more server instances, while vertical scaling (scale up) increases CPU/RAM on existing servers.
Which Python design pattern ensures a class has only one instance and provides a global access point to it?