# coding-parrot/low-level-design architecture

> Architecture diagram of the GitHub repository coding-parrot/low-level-design, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coding-parrot/low-level-design
- Repository: https://github.com/coding-parrot/low-level-design

## Overview

This repository is a small multi-module low-level design workspace. Each top-level module is a separate Maven project with its own source tree, tests, and build output, so the architectures are intentionally isolated rather than forming one shared application.

1. Repo-level structure  
The codebase is organized around four independent system-design exercises: distributed cache, distributed event bus, rate limiter, and service orchestrator. There is no shared runtime between them; the common pattern is a thin public API plus internal model classes, algorithms, and test scaffolding.

2. Distributed Cache module  
The cache module centers on `Cache` and `CacheBuilder`. `CacheBuilder` is the construction/binding layer for configuring policies, while `Cache` is the operational core that serves reads and writes. Supporting types under `models` define cache behavior such as eviction strategy, fetch strategy, record state, access metadata, and time abstraction.

3. Cache data flow  
The cache likely sits in front of a `DataSource`: read requests check the cache first, miss paths delegate to the data source, and writes update both the stored record and cache metadata. The `events` package (`Load`, `Write`, `Update`, `Eviction`) suggests the cache emits lifecycle events around these state changes, which makes it easy to reason about observability or policy hooks in the design.

4. Cache policy boundaries  
The presence of `EvictionAlgorithm` and `FetchAlgorithm` indicates the cache separates “what to do” from “how to do it.” That boundary is important for architecture diagrams: `Cache` orchestrates the flow, while strategy-like models decide eviction and fetch behavior. `Timer` plus `SettableTimer` in tests indicate time-based eviction or TTL logic is part of the design and is testable by injecting time.

5. Distributed Event Bus module  
The event bus module exposes `EventBus` as the primary entry point. Internally it uses `Subscription` and event models to manage publish/subscribe behavior, with `EventType` and `FailureEvent` representing the payload and failure path. This is a message-dispatch subsystem rather than a queue or broker implementation.

6. Event bus delivery model  
`KeyedExecutor` is the key architectural clue: events are likely routed through per-key execution lanes so related events preserve ordering while unrelated keys can process in parallel. The `RetryLimitExceededException` and `UnsubscribedPollException` classes show the bus has explicit delivery-state and retry semantics, so subscribers and polling are first-class lifecycle concerns.

7. Event bus timing and configuration  
The `util.Timer` abstraction and `application.properties` file indicate the bus has time-sensitive behavior and at least some configurable runtime settings. For a diagram, the main boundary is: producers publish to `EventBus`, subscribers register through `Subscription`, and failures/timeouts are handled through the retry and timer subsystems.

8. Rate Limiter module  
The rate limiter is centered on `TimerWheel`, `Request`, and `RateLimitExceededException`. The module is built around admission control: a request enters, the limiter decides whether it is allowed, and a rejection is surfaced via the exception path. The `Timer` utility and `TestTimer` show that time is abstracted for deterministic testing.

9. Rate limiting data flow  
`TimerWheel` suggests a time-bucketed or expiry-wheel implementation for tracking request windows efficiently. In architectural terms, requests are associated with timestamps or slots, the wheel advances with time, and expired counts are removed to enforce the configured limit. This makes the limiter stateful, time-driven, and optimized around fast updates rather than external storage.

10. Service Orchestrator module  
The service orchestrator models request routing across service instances. `LoadBalancer` is the entry point, `Router` defines the routing contract, and the `algorithms` package contains `WeightedRoundRobin` and `ConsistentHashing` as alternative placement strategies. The `models` package defines the domain objects: `Service`, `Node`, and `Request`.

11. Orchestration and routing boundaries  
This module cleanly separates topology from policy. `Service` and `Node` describe the available backend pool, while `Router` and the algorithm classes decide where a request should go. `WeightedRoundRobin` favors capacity-aware distribution, and `ConsistentHashing` favors stable key-to-node mapping, so the diagram should show a pluggable routing layer under the load balancer.

12. Cross-cutting implementation style  
Across all four modules, the design style is consistent: a single public facade, small domain models, strategy/policy objects, and test-focused time abstractions. There is little evidence of external infrastructure or network dependencies; the repo is primarily an in-memory LLD reference set meant to demonstrate system behavior, lifecycle boundaries, and algorithm choice rather than production deployment topology.

Main entry points: [`distributed-event-bus/src/main/java/EventBus.java`](https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/EventBus.java) (EventBus), [`distributed-cache/src/main/java/Cache.java`](https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/Cache.java) (Cache), [`rate-limiter/src/main/java/TimerWheel.java`](https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/TimerWheel.java) (TimerWheel), [`service-orchestrator/src/main/java/LoadBalancer.java`](https://github.com/coding-parrot/low-level-design/blob/master/service-orchestrator/src/main/java/LoadBalancer.java) (LoadBalancer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cache["Distributed Cache"]
  node_cache_builder["CacheBuilder<br/>[CacheBuilder.java]"]
  node_cache_core["Cache<br/>[Cache.java]"]
  node_cache_models["Policies<br/>cache model"]
  node_cache_events["Cache Events<br/>lifecycle events"]
  node_cache_source[("DataSource<br/>backend source<br/>[DataSource.java]")]
end

subgraph group_bus["Event Bus"]
  node_bus_api["EventBus<br/>bus facade<br/>[EventBus.java]"]
  node_bus_sub["Subscription<br/>[Subscription.java]"]
  node_bus_exec{{"KeyedExecutor<br/>ordered dispatcher<br/>[KeyedExecutor.java]"}}
  node_bus_models["Event Models"]
  node_bus_errors["Delivery Errors<br/>exceptions"]
end

subgraph group_rate["Rate Limiter"]
  node_rate_wheel{{"TimerWheel<br/>window engine<br/>[TimerWheel.java]"}}
  node_rate_request["Request<br/>admission model<br/>[Request.java]"]
  node_rate_timer(("Timer<br/>time abstraction<br/>[Timer.java]"))
  node_rate_error["Limit Error<br/>exception"]
end

subgraph group_orch["Service Orchestrator"]
  node_orch_lb["LoadBalancer<br/>routing facade<br/>[LoadBalancer.java]"]
  node_orch_router{{"Router<br/>routing contract<br/>[Router.java]"}}
  node_orch_algos{{"Placement Algo<br/>routing algorithms"}}
  node_orch_models["Topology<br/>service models"]
end

node_cache_builder -->|"builds"| node_cache_core
node_cache_core -->|"uses"| node_cache_models
node_cache_core -->|"misses"| node_cache_source
node_cache_core -->|"emits"| node_cache_events
node_cache_models -.->|"drives"| node_cache_events
node_bus_api -->|"manages"| node_bus_sub
node_bus_api -->|"dispatches"| node_bus_exec
node_bus_api -->|"publishes"| node_bus_models
node_bus_api -->|"signals"| node_bus_errors
node_bus_exec -.->|"orders"| node_bus_models
node_bus_sub -.->|"guards"| node_bus_errors
node_rate_wheel -->|"tracks"| node_rate_request
node_rate_wheel -->|"advances"| node_rate_timer
node_rate_wheel -->|"rejects"| node_rate_error
node_orch_lb -->|"delegates"| node_orch_router
node_orch_router -->|"implements"| node_orch_algos
node_orch_lb -->|"routes"| node_orch_models
node_orch_algos -.->|"uses"| node_orch_models

click node_cache_builder "https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/CacheBuilder.java"
click node_cache_core "https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/Cache.java"
click node_cache_models "https://github.com/coding-parrot/low-level-design/tree/master/distributed-cache/src/main/java/models"
click node_cache_events "https://github.com/coding-parrot/low-level-design/tree/master/distributed-cache/src/main/java/events"
click node_cache_source "https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/DataSource.java"
click node_bus_api "https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/EventBus.java"
click node_bus_sub "https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/models/Subscription.java"
click node_bus_exec "https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/lib/KeyedExecutor.java"
click node_bus_models "https://github.com/coding-parrot/low-level-design/tree/master/distributed-event-bus/src/main/java/models"
click node_bus_errors "https://github.com/coding-parrot/low-level-design/tree/master/distributed-event-bus/src/main/java/exceptions"
click node_rate_wheel "https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/TimerWheel.java"
click node_rate_request "https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/models/Request.java"
click node_rate_timer "https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/utils/Timer.java"
click node_rate_error "https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/exceptions/RateLimitExceededException.java"
click node_orch_lb "https://github.com/coding-parrot/low-level-design/blob/master/service-orchestrator/src/main/java/LoadBalancer.java"
click node_orch_router "https://github.com/coding-parrot/low-level-design/blob/master/service-orchestrator/src/main/java/algorithms/Router.java"
click node_orch_algos "https://github.com/coding-parrot/low-level-design/tree/master/service-orchestrator/src/main/java/algorithms"
click node_orch_models "https://github.com/coding-parrot/low-level-design/tree/master/service-orchestrator/src/main/java/models"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cache_builder,node_cache_core,node_cache_models,node_cache_events,node_cache_source toneBlue
class node_bus_api,node_bus_sub,node_bus_exec,node_bus_models,node_bus_errors toneAmber
class node_rate_wheel,node_rate_request,node_rate_timer,node_rate_error toneMint
class node_orch_lb,node_orch_router,node_orch_algos,node_orch_models toneRose
```

## Components

### Distributed Cache

Independent cache module with configurable policies and lifecycle events.

- [CacheBuilder](https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/CacheBuilder.java): builder · Configures cache policies and wires runtime dependencies. · `distributed-cache/src/main/java/CacheBuilder.java`
- [Cache](https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/Cache.java): cache core · Operational cache that serves reads, writes, and eviction. · `distributed-cache/src/main/java/Cache.java`
- [Policies](https://github.com/coding-parrot/low-level-design/tree/master/distributed-cache/src/main/java/models): cache model · Eviction, fetch, record state, access metadata, and time abstraction. · `distributed-cache/src/main/java/models`
- [Cache Events](https://github.com/coding-parrot/low-level-design/tree/master/distributed-cache/src/main/java/events): lifecycle events · Load, write, update, and eviction event flow around cache state changes. · `distributed-cache/src/main/java/events`
- [DataSource](https://github.com/coding-parrot/low-level-design/blob/master/distributed-cache/src/main/java/DataSource.java): backend source · Upstream source consulted on cache misses. · `distributed-cache/src/main/java/DataSource.java`

### Event Bus

Independent publish/subscribe dispatch module with ordered execution and retry handling.

- [EventBus](https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/EventBus.java): bus facade · Primary publish/subscribe entry point. · `distributed-event-bus/src/main/java/EventBus.java`
- [Subscription](https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/models/Subscription.java): subscription model · Tracks subscriber registration and delivery state. · `distributed-event-bus/src/main/java/models/Subscription.java`
- [KeyedExecutor](https://github.com/coding-parrot/low-level-design/blob/master/distributed-event-bus/src/main/java/lib/KeyedExecutor.java): ordered dispatcher · Routes events through per-key execution lanes to preserve ordering. · `distributed-event-bus/src/main/java/lib/KeyedExecutor.java`
- [Event Models](https://github.com/coding-parrot/low-level-design/tree/master/distributed-event-bus/src/main/java/models): event models · Event payloads, event types, and failure events. · `distributed-event-bus/src/main/java/models`
- [Delivery Errors](https://github.com/coding-parrot/low-level-design/tree/master/distributed-event-bus/src/main/java/exceptions): exceptions · Retry-limit and unsubscribe failure paths. · `distributed-event-bus/src/main/java/exceptions`

### Rate Limiter

Independent admission-control module driven by time windows.

- [TimerWheel](https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/TimerWheel.java): window engine · Time-bucketed request tracking for limit enforcement. · `rate-limiter/src/main/java/TimerWheel.java`
- [Request](https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/models/Request.java): admission model · Incoming request subject to rate checks. · `rate-limiter/src/main/java/models/Request.java`
- [Timer](https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/utils/Timer.java): time abstraction · Abstracted clock for deterministic tests and window progression. · `rate-limiter/src/main/java/utils/Timer.java`
- [Limit Error](https://github.com/coding-parrot/low-level-design/blob/master/rate-limiter/src/main/java/exceptions/RateLimitExceededException.java): exception · Raised when the configured limit is exceeded. · `rate-limiter/src/main/java/exceptions/RateLimitExceededException.java`

### Service Orchestrator

Independent routing module with pluggable placement algorithms.

- [LoadBalancer](https://github.com/coding-parrot/low-level-design/blob/master/service-orchestrator/src/main/java/LoadBalancer.java): routing facade · Entry point for service routing decisions. · `service-orchestrator/src/main/java/LoadBalancer.java`
- [Router](https://github.com/coding-parrot/low-level-design/blob/master/service-orchestrator/src/main/java/algorithms/Router.java): routing contract · Defines the routing interface used by the balancer. · `service-orchestrator/src/main/java/algorithms/Router.java`
- [Placement Algo](https://github.com/coding-parrot/low-level-design/tree/master/service-orchestrator/src/main/java/algorithms): routing algorithms · Weighted round robin and consistent hashing strategies. · `service-orchestrator/src/main/java/algorithms`
- [Topology](https://github.com/coding-parrot/low-level-design/tree/master/service-orchestrator/src/main/java/models): service models · Service, node, and request domain objects used for routing. · `service-orchestrator/src/main/java/models`

## Connections

- CacheBuilder → Cache: builds · Builder configures and constructs the cache runtime.
- Cache → Policies: uses · Cache depends on policies, records, and timer abstractions.
- Cache → DataSource: misses · Cache consults the upstream source on miss paths.
- Cache → Cache Events: emits · Cache publishes lifecycle events around load, write, update, and eviction.
- Policies → Cache Events: drives · Policy and record state determine lifecycle transitions.
- EventBus → Subscription: manages · Event bus registers and tracks subscriptions.
- EventBus → KeyedExecutor: dispatches · Published events are routed through keyed execution lanes.
- EventBus → Event Models: publishes · Bus carries event payloads and failure events.
- EventBus → Delivery Errors: signals · Delivery and polling failures surface through explicit exceptions.
- KeyedExecutor → Event Models: orders · Execution lanes preserve ordering for related events.
- Subscription → Delivery Errors: guards · Subscription state determines unsubscribe and retry failures.
- TimerWheel → Request: tracks · Requests are recorded into time windows or slots.
- TimerWheel → Timer: advances · Window expiry depends on the abstract clock.
- TimerWheel → Limit Error: rejects · Excess traffic is surfaced as a limit exception.
- LoadBalancer → Router: delegates · Load balancer delegates routing decisions to the router contract.
- Router → Placement Algo: implements · Routing contract is realized by placement strategies.
- LoadBalancer → Topology: routes · Balancer uses service, node, and request topology.
- Placement Algo → Topology: uses · Algorithms evaluate service topology and request keys.
