← 返回 doordash 的题目列表Bootstrap API Aggregating User, Payment, and Address Services
类型:online_judge
Implement a Bootstrap API that aggregates data from user, payment-card, and address services for a given user.
The dependency flow is:
userId -> UserService -> customerId
├-> PaymentService -> default card details
└-> AddressService -> address
In this executable version, no real HTTP calls are needed. Standard input provides mocked responses from all three services. Implement bootstrap_api and print the consolidated JSON object.
Input Format
Standard input contains one JSON object:
{
"userId": "user_001",
"userResponse": {
"status": 200,
"body": { "customerId": "cust_12345" }
},
"paymentResponse": {
"status": 200,
"body": {
"last_name": "Smith",
"first_name": "John",
"card_last_four": "4242"
}
},
"addressResponse": {
"status": 200,
"body": { "address": "123 Main St, San Francisco, CA 94102" }
}
}
userResponse is the response from UserService(userId); body.customerId is the customer ID.
paymentResponse is the response from PaymentService(customerId); its body is the default-card object.
addressResponse is the response from AddressService(customerId); body.address is the address string.
This executable version guarantees that all services return status = 200.
The card object may contain fields beyond those shown; preserve all of them in the output.
Output Format
Print one JSON object:
{
"CustomerId": "cust_12345",
"DefaultCard": {
"last_name": "Smith",
"first_name": "John",
"card_last_four": "4242"
},
"Address": "123 Main St, San Francisco, CA 94102"
}
After implementing the happy path, discuss how you would handle HTTP 500 responses, timeouts, exceptions, retries, graceful degradation, partial responses, and observability.
Example
Input
{"userId":"user_001","userResponse":{"status":200,"body":{"customerId":"cust_12345"}},"paymentResponse":{"status":200,"body":{"last_name":"Smith","first_name":"John","card_last_four":"4242"}},"addressResponse":{"status":200,"body":{"address":"123 Main St, San Francisco, CA 94102"}}}
Output
{"CustomerId":"cust_12345","DefaultCard":{"last_name":"Smith","first_name":"John","card_last_four":"4242"},"Address":"123 Main St, San Francisco, CA 94102"}