RETURN TO SYSTEM DESIGN VAULT (55)BLUEPRINT #31 // Very Hard
#31Very HardCore Distributed Systems

Design an IoC/Dependency Injection Framework

ASKED IN INTERVIEWS AT:ADPFAANG

EXECUTIVE SUMMARY & PROBLEM STATEMENT

Architect a robust, compile-time or runtime Inversion of Control (IoC) container that resolves complex dependency graphs, circular dependencies, and component lifecycles.

SCALE ESTIMATION & TRAFFIC ENVELOPE

DAILY ACTIVE USERS / TPSInternal runtime framework: millions of resolutions per second
READ / WRITE TRAFFIC RATIOWrite once during app bootstrap, read on every injection
5-YEAR STORAGE CAPACITYIn-memory dependency graph registry

FUNCTIONAL REQUIREMENTS

  • [1]Register beans and providers with scope definitions
  • [2]Resolve dependencies recursively on request
  • [3]Detect and reject circular dependencies

NON-FUNCTIONAL REQUIREMENTS

  • •Sub-microsecond resolution overhead
  • •Minimal startup time
  • •Thread-safe concurrent resolutions

CORE ARCHITECTURAL COMPONENTS

Registry Container
Topological Dependency Sorter
Singleton Instance Cache
Scope Context Manager
Proxy Bytecode Generator

DATA SCHEMA & PERSISTENCE

BeanDefinition { type, factoryFn, scope, dependencies: Type[], instanceRef }

DISTRIBUTED TRADE-OFFS & FAILURE MODES

  • ⟡Compile-time annotation processing (Dagger) eliminates startup reflection overhead; runtime containers (Spring) provide dynamic flexibility.