Create a REST API that exposes the following endpoint:
GET /api/bootstrap
Request Input
- User Id
Response
- Address Data: address including the user’s name, street, city, state, and zip
- Consumer Data
- Consumer Roles
- Payment Data
- Default Payment Card
- Gift card credits available
This endpoint needs to request and aggregate Address Data, Consumer Data, and Payment Data from internal DoorDash services.
When the DoorDash app starts up on mobile devices, it needs to fetch some data about the user in order to proceed past the initial splash screen.
If the mobile client does not get a 2xx status code response, the user is unable to proceed past the splash screen, resulting in a bad user experience.
You are tasked with implementing an API that exposes the required information and is as resilient to failures as possible in order to ensure a good user experience.
Expected response if all dependencies are available:
{
"consumerId": "1bef988e-e544-11ed-b5ea-0242ac120002",
"roles": [],
"defaultCard": {
"lastFourDigits": "1234",
"expirationYear": "2024",
"expirationMonth": "01",
"fingerPrint": "f3cd76f4-e544-11ed-b5ea-0242ac120002",
"createdAt": "2022-07-15"
},
"availableGiftCardCredits": "0.0",
"address": "Foo Bar, 303 2nd Street, San Francisco, CA 94105"
}
Internal APIs:
GET /api/consumers/{userId}GET /api/payment_methods/{consumerId}GET /api/address/{consumerId}
这道 DoorDash 面试题考察的是聚合型 REST API 的设计:对外提供一个 /api/bootstrap 接口,内部并行调用用户、地址和支付三类服务,再把结果组装成移动端启动页所需的统一响应。题目重点不在复杂算法,而在服务编排、容错和返回值设计:只要核心依赖可用,就要尽量返回 2xx,避免应用卡在 splash screen。实现时通常会根据 userId 先查 consumer,再用 consumerId 去拉取 payment_methods 和 address,最后合并出 roles、defaultCard、gift card credits 和拼接后的地址字符串。