Why AWS S3
We are selecting AWS S3 because it provides scalable, secure, and highly durable object storage, while aligning with our AWS ecosystem strategy and long-term scalability goals.
Key Reasons
- Reduces backend and database load
- Lightweight REST API payloads
- Direct client upload using Pre-Signed URLs
- Secure authentication and authorization flow
- CDN support through CloudFront
- Future image optimization support (thumbnail / medium / large variants)
- Easier long-term maintenance by staying within the AWS ecosystem
Why Not Store Images as Blob in Database
❌ Traditional approach:
Database (Blob)
│
Image Binary
▼
Spring Boot API
│
Heavy REST Payload
▼
Browser / Mobile
Problems
- Larger database size
- Heavy REST API payloads
- Backend transfers image bytes on every request
- Higher memory and bandwidth usage
- Database backup/restore becomes expensive
- Scaling becomes difficult
Recommended Architecture
Keep binary files in S3, metadata in database.
product_images
--------------
id
product_id
image_url
s3_key
filename
filesize
filetype
created_at
Image bytes never enter PostgreSQL.
Secure Upload Flow
IMAGE UPLOAD FLOW
┌─────────────────┐
│ Client │
│ Web / Mobile App │
└────────┬────────┘
│
│ 1️⃣ Upload Request
│ JWT / Session Token
▼
┌────────────────────────────────┐
│ Spring Boot + Spring Security │
│ │
│ ✔ Authentication │
│ ✔ Authorization │
│ ✔ Validate Content Type │
│ ✔ Generate Pre-Signed URL │
└────────────┬───────────────────┘
│
│ 2️⃣ Temporary Upload URL
▼
┌──────────────┐
│ Amazon S3 │
└──────▲───────┘
│
│ 3️⃣ Direct Upload
│ Secure temporary access
│ Image never touches backend
│
┌─────────────┴─────────────┐
│ Client │
└─────────────┬─────────────┘
│
│ 4️⃣ Save Metadata
│ image_url
│ s3_key
│ filename
▼
┌────────────────┐
│ PostgreSQL │
└────────────────┘
Security Benefits
Backend responsibilities:
- Authentication
- Authorization
- File validation
- Generate temporary secure upload URL
- Store metadata only
S3 responsibilities:
- Secure object storage
- Temporary Pre-Signed URL access
- IAM permissions
- Encryption
- Private object support
Backend never exposes AWS credentials.
Image Fetch Flow (Optimized)
Client (Web / Mobile)
│
│ GET /products
▼
Spring Boot API
│
│ Product Data + Image URL only
│ Lightweight REST payload
▼
PostgreSQL
Response:
{
"name": "Nike Shoes",
"price": 2999,
"imageUrl":
"https://cdn.app.com/products/123.jpg"
}
│
│ Browser loads image URL
▼
Nearest CloudFront CDN Edge
(Cache Hit → Instant response)
│ Cache Miss
▼
Amazon S3
Performance Benefits
REST API transfers:
✅ Product metadata only
{
"name": "Nike Shoes",
"price": 2999,
"imageUrl": "https://cdn.app.com/products/123/main.jpg"
}
NOT:
❌ Image binary data
Benefits
- Smaller REST payloads
- Lower backend CPU usage
- Lower bandwidth consumption
- Faster API responses
- Better scalability during traffic spikes
CDN Optimization (Future Scale)
Future architecture:
Client
│
▼
Nearest CloudFront Edge Location
(Cache Frequently Requested Images)
│ Cache Miss
▼
Amazon S3
Benefits
- Users receive images from nearest CDN edge location
- Frequently accessed resources remain cached
- Lower latency globally
- Faster image loading
- Reduced origin load
- Better UX
- Better SEO
- Lower infrastructure cost
Future Image Optimization
Current:
product.jpg (1200px)
Future pipeline:
Upload Original
│
▼
Amazon S3
│
Lambda / Image Processor
▼
thumbnail.jpg (300px)
medium.jpg (600px)
large.jpg (1200px)
Examples:
Product Listing:
cdn.app.com/products/123?size=thumbnail
Product Details:
cdn.app.com/products/123?size=large
In practice, CloudFront can forward these query parameters, and a Lambda image service can return the correct variant while keeping the same clean URL structure.
Why
- Product list page does not need high-resolution images
- Lower bandwidth usage
- Faster mobile experience
- Better rendering performance
Why AWS S3 over Other Storage Solutions
| Criteria | AWS S3 | EdgeStore | Google Cloud Storage |
|---|---|---|---|
| Highly scalable object storage | ✅ | Depends provider | ✅ |
| Secure upload flow | ✅ Native | Depends implementation | ✅ |
| CDN ecosystem | CloudFront | External setup | Cloud CDN |
| AWS ecosystem integration | Excellent | Neutral | Limited |
| Future scale readiness | Excellent | Moderate | Excellent |
| IAM & security controls | Strong | Depends provider | Strong |
| Durability | 99.999999999% | Depends provider | High |
Final Decision
AWS S3 is selected because it provides scalable, secure, and highly durable object storage while reducing REST payload size, eliminating backend image transfer bottlenecks, enabling secure direct uploads, supporting global CDN delivery, and providing a future-proof architecture for ecommerce scale.
Top comments (0)