AceBackend
MediumAPI Design / Microservices

Build a Backend-for-Frontend (BFF)

Fan-out/fan-inGraceful degradationRequest tracing
Your frontend needs a single API call to render a dashboard, but the data lives across three independent backend services:
- User Service — returns the current user's profile and preferences
- Catalog Service — returns available items with metadata (title, description, category)
- Activity Service — returns the user's recent activity and notifications
Your job is to build a BFF (Backend-for-Frontend) that:
1. Receives a single GET /v1/pages/home?user_id=abc request from the client
2. Calls all three downstream services in parallel
3. Assembles everything into a single JSON response with a section per service
4. If a downstream call fails or times out, that section returns an error field instead of failing the entire response
5. Total response time must be under 500ms even if one service is slow
The downstream service URLs are provided via environment variables (USER_SERVICE_URL, CATALOG_SERVICE_URL, ACTIVITY_SERVICE_URL).
Constraints
All downstream calls must be concurrent (goroutines / threads / async)
Per-service timeout: 300ms
Overall request timeout: 500ms
A failed or slow service must not break the entire response — degrade gracefully
Must propagate X-Request-Id header to all downstream calls (generate one if missing)
Hints
Test Cases (6)
1. All services healthy
Response contains all three sections with data
2. One service returns 500
That section has error field, others are fine
3. One service takes 2 seconds
That section times out, others return normally
4. All services healthy — check latency
Total response time < 500ms (parallel, not sequential)
5. Missing X-Request-Id
BFF generates one and propagates it to all downstream calls
6. A service returns empty data
Section has empty items: [], not an error
Solution
Loading editor...
Test Results
Click "Run Tests" to execute your solution
AceBackend — Master Backend Engineering Interviews with Real Code