Design a Photo Upload and Viewing Component
Problem Statement
Designing a Photo Upload and Viewing Component that allows users to upload, store, and view images (like profile pictures, gallery uploads, or post photos) in a web or mobile application.
The system should support efficient upload handling, image transformations (compression, resizing, thumbnails), secure storage, and fast retrieval for display.
π― Objective
Build a scalable, fault-tolerant, and performant photo management system that supports:
β Functional Requirements
1. Photo Upload
2. Image Processing
3. Storage
4. Photo Retrieval & Viewing
5. Access Control
6. Deletion and Lifecycle
7. Analytics (Optional)
βοΈ Non-Functional Requirements
| Category | Description |
| --------------------- | -------------------------------------------------------------------- |
| **Scalability** | Support millions of uploads and billions of views. |
| **Availability** | 99.9% uptime for image retrieval. |
| **Durability** | Store photos reliably with redundancy (e.g., 11 nines on S3). |
| **Performance** | Upload and retrieval latency < 300ms via CDN. |
| **Security** | Encrypted uploads, signed URLs, and access control. |
| **Cost Optimization** | Use tiered storage (standard, infrequent access, archival). |
| **Extensibility** | Allow integration with tagging, album creation, or sharing features. |
π§ Key Components to Design
1. Upload Service
2. Image Processing Service
3. Storage Service
1
2/user_id/
3 original/
4 thumbnail/
5 medium/
6 full/4. Metadata Service
5. CDN & Caching Layer
6. View Service / API
7. Notification Service (Optional)
π§± High-Level Architecture
1
2 ββββββββββββββββββββββββ
3 β Web / Mobile App β
4 ββββββββββββ¬ββββββββββββ
5 β
6 βββββββββ΄ββββββββββββββ
7 β API Gateway β
8 βββββββββ¬ββββββββββββββ
9 β
10 βββββββββββββββββββΌβββββββββββββββββββββββββββββ
11 β β β
12 β Upload Service View Service
13 β β β
14 β Image Processing Service Metadata Service
15 β β β
16 βββββββββββββββββββΌβββββββββββββββββββββββββββββ
17 β
18 ββββββββββββ΄βββββββββββ
19 β Message Queue (MQ) β
20 ββββββββββββ¬βββββββββββ
21 β
22 ββββββββββββ΄βββββββββββ
23 β Object Storage + β
24 β CDN Distribution β
25 βββββββββββββββββββββββπΎ Data Model Example
Photo Table
| Field | Type | Description |
| ------------- | --------- | ---------------------------------- |
| photo_id | UUID | Unique photo identifier |
| user_id | UUID | Owner reference |
| url_original | String | Link to original photo |
| url_thumbnail | String | Thumbnail variant |
| url_medium | String | Medium-size variant |
| visibility | Enum | PUBLIC / PRIVATE |
| status | Enum | UPLOADING / PROCESSING / AVAILABLE |
| created_at | Timestamp | Upload time |
| updated_at | Timestamp | Last updated |
β‘ Scalability & Performance Considerations
π Security Considerations
β οΈ Failure Scenarios
| Failure | Mitigation |
| ------------------------ | ---------------------------------------------- |
| Upload interrupted | Resume upload using multipart upload |
| Image processing failure | Retry via queue with exponential backoff |
| CDN cache miss | Fetch from object storage and refresh cache |
| Unauthorized access | Validate JWT + enforce ACL before serving URLs |
β Expected Outcome
A highly scalable, secure, and responsive Photo Upload and Viewing Component that: