notion->link (same as readme)
Design an In-Memory Distributed Queue like Kafka.
- The queue should be in-memory and does not require access to the file system.
- There can be multiple topics in the queue.
- A (string) message can be published on a topic by a producer/publisher and consumers/subscribers topic to receive the messages.
- There can be multiple producers and consumers.
- A producer can publish to multiple topics.
- A consumer can listen from multiple topics.
- The consumer should print "<consumer_id> received " on receiving the message.
- The queue system should be multithreaded, i.e., messages can be produced or consumed in parallel producers/consumers.
- User should be able to add topic
- User should be able to add producers 3. User should be able to add consumers
- User should be able to publish message
- System should be able to consume message
- Create Producer
- Create Consumer
- Create Topic
- Publish Message
- Consume Message
- Security
Entity (subclasses)Technical naming Domain naming
- Topic
- Queue
- Message
- Producer (Technical) or Publisher
- Consumer (Technical) or Subscriber
Entity(Composition, properties, etc)
- Queue (List topics)
- Message(String msg)
- Consumer (int id)
- KISS
- Separation of concern
- DRY
- Code for the maintainer - Modular
- Minimize coupling and maximize cohesion
- Composition over inheritance
- SOLID
- Singleton QueueService, QueueMediator
- Mediator QueueMediator
- Push mechanism only BlockingQueue
- Push mechanism only Wait Notify Mechanism
- Multithreading Lock Reentrant lock instead of synchronized block.
- Push based approach from Topic to Consumer
- Pull based approach Consumer pulls from the topic preferable and implemented
- Support for multithreading
-
In memory and distributed?
Not in scope.
-
Is there a limit on message size?
- 64kb, 1MB → network - POST, GET.
- We don't have limits
- Kafka 1M event size.
- 1K is just enough? 1K, 10x-> 10KB
-
In memory solution. What if the memory is full?
- We haven't set any limit?
- OOM in the current implementation fail fast.
- Can we set a limit on number of messages the system take?
- 1M messages I can have in the queue.
- Code update will be required for this.
- We haven't set any limit?
-
TTL to old data?
- As of now, it's not there.
- We can design it.
-
LLD, Is it low latency or high throughput. Maybe like Active MQ.
- very low latency - 10ns
- on a single throughput depend on how big your personal computer.
- 100K QPS in memory.
-
Class loader for class and static initize.
JVM
-
Regarding interface split and join, what is the right leveling?
- The right balance of interface split or join
- The right balance abstractions (almost useless) vs implementations (too complex)
- Vehicle correlated
- drive
- brake
- fillFuel
- openDoor
- closeDoor
- repairable
8/18
9/18
Mediator pattern: Concept & Coding-LLD