$ show lavakumarThatisetti/Machine-Coding-Round
This repository is a curated collection of low-level design (LLD) and machine coding round solutions, primarily targeting interview preparation. It contains over 15 self-contained subprojects, each modeling a classic system design problem such as chess, elevator control, Uber ride booking, Splitwise expense splitting, parking lot, stock broker, task scheduler, Kafka message queue, in-memory key-value store, and more. Each subproject follows a consistent architecture with domain models, repository interfaces with in-memory implementations, service classes, and often a Main or Demo class for standalone execution. The code heavily employs design patterns like Strategy, Factory, Repository, and Observer, and demonstrates concurrency handling with locks, atomic variables, and thread-safe collections. The collection is not intended for production deployment; all state is volatile and stored in-memory. While the quality is uneven across subprojects, many exhibit clean separation of concerns and extensible design. The repository serves as a practical study resource for object-oriented design, with problem statements and video tutorials linked in the README. Some subprojects have multiple iterations (e.g., Kafka from simple to production-grade) showing evolution, but this also introduces duplication and occasional inconsistencies in naming and package structure. Despite the lack of automated tests and incomplete implementations in a few areas, the overall codebase demonstrates solid craftsmanship for educational purposes. A handful of modulesβsuch as the distributed cache with consistent hashing, the circuit breaker for resilience, the order matching engine, and the heap-based feed fetch strategyβare particularly well-isolated and could be extracted for reuse in other projects with minimal adaptation.
The LLM identified 6 files worth highlighting for reuse:
Implements consistent hashing with virtual nodes for key distribution across cache nodes. Handles node addition and removal with minimal key redistribution. Clean, self-contained, and easily reusable for any distributed load-balancing or sharding scenario.
A generic circuit breaker with state transitions (CLOSED, OPEN, HALF_OPEN), failure counting, and threshold-based reset. Thread-safe using AtomicReference. Extractable as a library component for any system needing fault-tolerant external calls.
Uses a priority queue to merge multiple sorted timelines (e.g., from followed users) into a single ranked feed. Demonstrates efficient O(N log K) merging without fetching all posts. The strategy interface allows swapping implementations, making it a clean reusable pattern for any sorted data consolidation.
Implements price-time priority matching for buy and sell orders. Uses an OrderBook that maintains price levels and per-level FIFO queues. The engine matches incoming orders against the book, producing trades and updating holdings. Well-isolated logic; can be reused for any exchange or auction system.
An abstract factory that creates chess piece instances (Pawn, Rook, etc.) based on color and type. Encapsulates piece creation, hiding concrete classes. Easily extensible for new variants. Demonstrates the Factory pattern cleanly without external dependencies.
Implements the SplitCalculator interface for equal split of an expense amount among participants. Rounds and adjusts for remainder to ensure total sums correctly. The strategy pattern allows swapping split algorithms (exact, percent) via a factory. Self-contained and applicable to any bill-splitting domain.