Skip to content

brzzznko/CommentsSystem

Repository files navigation

Interview task

See Description for full task requirements.

See Setup Instructions to get the project running

Proposed System Architecture

Services

  • comment-service

    • Exposes REST API to submit and retrieve paginated comments

    • Stores comments in MongoDB

    • Publishes new comments to Kafka via transactional outbox

  • notification-service

    • Maintains WebSocket connections with clients

    • Consumes messages from Kafka

    • Publishes to Redis Pub/Sub for all client fanout

    • Forwards comments to connected clients in real time

Messaging

  • Kafka is used to propagate new comments between services

  • Redis Pub/Sub enables WebSocket fanout to multiple clients

Flow

  1. Client submits a comment to comment-service

  2. Comment is stored in MongoDB

  3. Event is published to Kafka

  4. notification-service consumes the message

  5. The comment is pushed to Redis Pub/Sub

  6. Connected WebSocket clients receive the update

Note

For simplicity, Kafka processor and WebSocket logic are combined in notification-service for this task.

Setup Instructions

1. Build the Project

From the root directory, run:

./gradlew clean build

This builds all microservices and runs integration tests.

2. Start the Environment

Use Docker Compose to spin up Kafka, Redis, MongoDB, and all services:

docker-compose up --build -d

Wait until all services are running (Kafka topic will be auto-created).

What Gets Deployed (and Why)

The Docker Compose setup includes:

  • comment-service: REST API + MongoDB storage + Kafka producer

  • notification-service-1 and notification-service-2: Kafka consumers + Redis publishers + WebSocket push

  • kafka: With 2 partitions for comment events

  • redis: For broadcasting to clients via Pub/Sub

  • mongo: For comment persistence

Two instances of notification-service are used to simulate partitioned Kafka consumption. Each instance processes messages from one partition (same consumer group), and both publish to Redis. This lets all WebSocket clients receive all comments — no matter which partition they were sent to.

3. Open the Client UI

Open two or more browser windows and navigate to:

http://localhost:8080/client.html
http://localhost:8080/second-client.html

Each browser will: - Assign a unique anonId via localStorage (better set to 1 and 2 manually, to check fanout) - Load existing comments from the backend - Establish a WebSocket connection for real-time updates

You can test by submitting a comment in one tab and seeing it appear in the others.

4. Run End-to-End Tests (Optional)

If you want to run E2E Selenium tests:

./gradlew e2eTestAll

Note: Docker Compose must be running.

5. Stop the System

To stop all services and remove associated volumes:

docker-compose down -v

This shuts down all running containers and cleans up any persisted MongoDB, Kafka, and Redis data.

Description

Build a service that will provide us with basic functionality to manage web page comments.

Instructions

  • Create a simple webpage (e.g., page.html) with a minimal UI design that will:

    • List all available comments

    • Have an input field to add a new comment

  • Create the backend endpoints to facilitate the need for the above page

  • Adding a comment must be an asynchronous operation

  • The application should store the comments in a database

  • The application should push the comments to the client’s browser and displayed in a UI

  • The system must be composed of two or more microservices communicating over a messaging system

  • Design an event-driven and scalable architecture. Services need to have clear responsibilities and well-defined contracts.

  • The services should be written in Java using the Spring Boot framework

  • The services should have the necessary testing coverage

Deliverables

  • Push the project’s source code and its documentation to the git repository provided.

  • Documentation must include detailed information on how to deploy and run the project.

Notes

  • The exercise will be evaluated mainly based on:

    • Design patterns used

    • Test strategies used (consider adding integration test or automated end-to-end test or propose a manual test flow)

    • Test coverage and good development practices used

    • Understanding and usage of messaging systems

  • UI is not the main objective of this task. You can use any technology and make it simple, but it must be functional enough.

  • Push the code to the repository After completing a component or milestone to avoid one big bang.

  • Do not worry if you haven’t completed all the task parts. We have all been here before.

  • Reach out to us if you have any questions.

About

Scalable microservice comment system design

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published