KatInterview

Building a Production CI/CD System with Custom Job Orchestration

System DesignModel answer
HardModel answerSystem Designci-cddistributed-systemsscheduling

Last updated

Design a complete continuous integration and delivery platform for a large monorepo, with emphasis on the job scheduler that coordinates pipeline execution.

You're building a continuous integration and delivery platform for an engineering organization that maintains multiple microservices in a single large repository. Design the complete system architecture and explain your decisions across all layers.

Your design should address:

  1. Version control integration — How the system connects to source control, what events trigger pipelines (code pushes, pull requests, releases, scheduled runs), how you handle repository-specific concerns like detecting which services changed in a monorepo, and branch protection requirements.

  2. Build execution and artifact storage — How build jobs run (execution environments, isolation), how you ensure builds are reproducible, how build outputs and dependencies are cached, where artifacts are stored, and how long you retain them.

  3. Test automation — The different test stages (unit, integration, end-to-end), how tests run in parallel, how you create isolated test environments for pull requests, and your strategy for handling unreliable tests that sometimes fail without code changes.

  4. Execution environments — When to use containers versus virtual machines for running jobs, and how you guarantee that builds produce the same output given the same input.

  5. Deployment approaches — Different strategies for releasing new versions (all-at-once updates, gradual rollouts, maintaining two versions simultaneously), how you use feature toggles, and how to safely update databases when the schema needs to change.

  6. Rollback and monitoring — How you detect that a deployment has problems, how you automatically revert to the previous version, what telemetry you collect, and how incidents are escalated.

  7. Security and compliance — How you scan for vulnerabilities and secrets, how you prove what went into each build, how you sign artifacts, how you control what can be deployed, and how you audit actions taken by the system.

  8. Job scheduler design (the core system design challenge) — Design the service that orchestrates pipeline execution. This includes how you model dependencies between jobs (directed graphs), how you limit concurrent executions, how you prioritize work across teams, how you retry failures, how you cache results, and how you prevent any single team from monopolizing resources. Specify the data model, the storage systems you'll use, the APIs, and the key algorithms.

  9. Scale and isolation — How the platform scales to support many teams, how you prevent one team's workload from affecting another, and how you enforce resource limits.

  10. Efficiency and reliability — How you reduce costs (using interruptible compute, reusing cached work), and how you design the platform itself to stay available even when components fail.

  11. Metrics and operational readiness — What indicators you track to measure both delivery performance and platform health, and how an on-call engineer would respond to common failures.

Walk through the important trade-offs in your design (speed versus control, single repository versus many repositories, push-based versus pull-based deployments). Describe several failure scenarios and explain how your design handles them.

Hints

Hint 1

Start by establishing assumptions about scale: number of engineers, services, daily pipeline runs, and throughput requirements. These numbers will justify your design choices.

Hint 2

The scheduler is the most complex component. Focus your time there: model the dependency graph, design the state machine for jobs, choose your storage layer, and explain how you ensure exactly-once execution.

Hint 3

For the deployment layer, think through what happens when a release causes errors. How do you detect the problem automatically? How do you roll back without human intervention?