Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 1.88 KB

File metadata and controls

27 lines (21 loc) · 1.88 KB

Scalability Strategy & Design Decisions

1. Architecture: Modular Monolith vs. Microservices

The current application is built as a Modular Monolith. This is the optimal starting point for scalability:

  • Codebase: Organized by feature (Auth, Tasks) rather than technical layer.
  • Scalability Path: As specific modules (e.g., Task Processing) experience high load, they can be easily extracted into separate microservices.

2. Horizontal Scaling (Statelessness)

The backend is designed to be Stateless:

  • Authentication: Usage of JWT (JSON Web Tokens) instead of server-side sessions means any server instance can verify a request.
  • Scaling Strategy: We can spin up multiple instances of this Node.js server behind a Load Balancer (e.g., Nginx, AWS ALB). Traffic is distributed across instances, allowing the system to handle thousands of concurrent requests.

3. Database Optimizations

  • Indexing: MongoDB schemas should have indexes on frequently successfully queried fields (e.g., email for users, user ID for tasks).
  • Caching: For a production environment, we would implement Redis to cache:
    • User sessions (if needed for invalidation).
    • Frequently accessed task lists.
  • Replica Sets: Use MongoDB Replica Sets for high availability and read/write splitting (directing read operations to secondary nodes).

4. Asynchronous Processing

  • For heavy operations (e.g., generating PDF reports of tasks, sending implementation emails), we would introduce a Message Queue (e.g., RabbitMQ, BullMQ).
  • The API would offload the work to the queue and respond immediately to the user, preventing the main thread from blocking.

5. Security & robustness

  • Rate Limiting: express-rate-limit should be added to prevent abuse.
  • Input Validation: implemented using express-validator to ensure data integrity before it reaches the core logic.