Design Progress Bar Functionality

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-02-13

Problem Statement

Design a Progress Bar System that visually and programmatically tracks and displays the progress of long-running operations (like file uploads, downloads, data processing, or report generation) in real-time.


This problem assesses your ability to design responsive, observable, and scalable system components that handle real-time progress updates across distributed systems or applications.


🧾 Context


Modern applications frequently involve long-running tasks — such as:


•Uploading large files
•Installing software packages
•Video transcoding
•Bulk database migrations or data imports


Users expect to see real-time progress feedback on these tasks, improving user experience and system observability.


You need to design a Progress Bar Service that:


•Tracks task progress at multiple stages
•Updates clients in real-time
•Handles partial failures and retries gracefully


📋 Functional Requirements


1.Task Registration
•Allow clients to create/register a long-running task.
•Each task gets a unique taskId.
2.Progress Update
•Components or background workers can send periodic progress updates (0–100%) for the task.
3.Progress Query
•Clients can query the current progress status of a task via an API.
4.Real-time Notification
•Optional: Support real-time progress updates through WebSockets, Server-Sent Events (SSE), or message queues.
5.Completion Handling
•When a task reaches 100%, mark it as complete and record completion time.
6.Error Handling
•If a task fails, update its status as failed with an error message.


⚙️ Non-Functional Requirements


AttributeDescription


Scalability


Should support thousands of concurrent progress-tracked tasks.


Reliability


Progress updates must not be lost even during transient network failures.


Low Latency


Real-time updates should reflect quickly in the UI (<1s lag).


Extensibility


Easy to add support for new update mechanisms or notification channels.


Persistence


Must persist progress state for recovery after restarts.


🧱 High-Level Architecture Components


1.Client/UI Layer
•Displays the progress bar UI for active tasks.
•Subscribes to real-time updates (e.g., WebSocket/SSE).
2.Progress Service (Core Component)
•Manages creation, update, and retrieval of task progress.
•Exposes REST and/or WebSocket APIs.
3.Task Worker/Executor
•Executes the long-running operation and periodically sends progress updates to the Progress Service.
4.Message Queue / Pub-Sub (optional)
•Used for asynchronous progress updates (e.g., via Kafka, Redis Streams).
5.Storage Layer
•Stores task metadata, progress, timestamps, and status.
6.Cache (Redis/Memcached)
•Stores frequently updated progress values for quick retrieval.


🧩 Example Architecture Diagram (Textual)

1 2[Client/UI] <--> [API Gateway] 3 | 4 [Progress Service] 5 | 6 -------------------------------- 7 | | 8 [Cache Layer] [Database] 9 | 10 [Task Worker(s)] ---> [Message Queue] ---> [Progress Service Updates]


🧠 Data Model Example


FieldTypeDescription


taskId

UUID

Unique identifier for the task


status

Enum(Pending, Running, Completed, Failed)

Task lifecycle state


progress

Float

Percentage completion (0–100)


message

String



Optional message (e.g., “Uploading file 3/10”)


lastUpdated


Timestamp


Last progress update time


errorMessage


String


Optional error message if failed


🔄 Flow of Execution


1.Client starts a long-running operation and registers a task via API → POST /tasks.
2.Progress Service creates a record and returns a taskId.
3.Worker begins processing and sends periodic updates via POST /tasks/{taskId}/progress.
4.Progress Service updates the cache and notifies subscribed clients (via WebSocket/SSE).
5.Client UI updates the progress bar accordingly.
6.On completion, Worker sends a final update (progress=100%, status=Completed).


📡 Example API Design


MethodEndpointDescription


POST

/tasks

Create/register a new task


POST

/tasks/{taskId}/progress

Update progress percentage


GET

/tasks/{taskId}

Retrieve current status/progress


WS

/tasks/{taskId}/subscribe

Subscribe for real-time updates


⚙️ Technology Choices


LayerOptions


Backend

Node.js, Spring Boot, Go


Storage

PostgreSQL, DynamoDB, MongoDB


Cache

Redis


Pub/Sub

Kafka, RabbitMQ, Redis Streams


Real-time updates

WebSocket, SSE, gRPC streams


Frontend

React/Vue/Angular (Progress Bar UI component)


📊 Scalability Considerations


•Sharding tasks by ID prefix for distributed storage.
•Use Redis for ephemeral progress states and DB for durability.
•Apply TTL (time-to-live) for completed task records.
•Introduce rate limiting for worker updates to avoid excessive traffic.


🚀 Future Enhancements


•Support multi-stage progress (e.g., “Downloading → Processing → Uploading”).
•Add notifications on task completion/failure (via email or push).
•Integrate Prometheus/Grafana metrics for monitoring system health.
•Support progress aggregation across subtasks or distributed jobs.


💬 Discussion Points for Interview


•How would you handle real-time updates efficiently to thousands of clients?
•How do you ensure data consistency between cache and database?
•What’s your strategy for handling failed updates or dropped connections?
•How would you design a multi-node system that scales horizontally?


Solution

Comments