Design GoPuff

System DesignE-commerce & PaymentsGeo & Maps

Materials — open to everyone, no sign-in

Topic: Design GoPuff

Interviewer: ken

Level: L6 (Staff)

Additional Resources:


System Design Interview - System Design

11/4/2024

YouTube for the event:

Coach Ken LinkedIn:

https://commitway.com/linkedin

WeChat QRCodes

| | | 职场提升俱乐部 |

Functional requirements

Local delivery from fulfillment center nearby under 1 hour

Ordering (more important than search)

Search

Scale

100M DAU

10k fulfillment center

20M Items sold daily

1k cities

10k SKUs

1k QPS

[40]

[39]

Operational flow

Ramen noodle

Which warehouse can fulfill the order

Order that warehouse to pick the order

Warehouse doesn’t have the inventory

Find inventory availability within range

[36]

[search?]

[auth credit card?]

How to locate the inventory and book the inventory.

[34]

Inventory data:

SKU, warehouseID, total qty, reserved qty,

Q: how to find items available nearby?

A: similar to the above.

10k SKU

Recommendation system, precompute the preference

Fetch from precompute service

Filter by availability

[29:46]

Ordering

1k QPS - lots of contentions

Some concurrency control

Lock database rows (pessimistic)

Optimistic, abort concurrent writes

How much conflict on single SKU

Optimistic concurrency control will be more efficient

PostGre SQL offers it

[26:36]

10k SKUs x 10k cities x 50 = 5GB

Optimistic control to reserve item

[24:30]

Warehouse service

Pick/pack operation

Q: payment process?

Payment goes through. Send to warehouse

Payment may fail

System needs to invalidate the reservation

[21]

[storing order?]

[1. Draw web client]

[2.

[18]

Interviewer:

Add to cart

Checkout

Add payment instrument

Pay

Payment -> put in payment queue -> update inventory (make reservation permanent)

Fail -> remove reservation

Reserve inventory

Authorize credit card

Success

Ship inventory

Failure

Unreserve inventory

Can use SQL or NoSQL

Mongo/Cosmos

Optimistic control - similar to transaction

May operate on 2 partitions of inventory

SKU, location, Inventory status: available -> temp hold -> ready to ship -> shipped -> received

Q: Order table:

userID, orderID, skuList({sku: qty}), status

status(pending->temp reserved->ordered->picked/packed/delivered)

[when to reserve?]

Payment is async. How to update the inventory?

[14]

Q: Add one item to the shopping cart, then we will reserve the item?

A: If no inventory, cannot add to shopping cart

Reserve when constructed shopping cart

[10]

Then send the payment into message queue

Then process payment

Then update the inventory

What do we put in the rowKey

Next request, also supply the rowKey

[6:51]

[ Lost reservation expiration for the second user? ]

Remove reservation expiration field

[5]

Put it into order

Timestamp for the status

Add a service to clean up pending order

[4]

What happens when a user clicks “pay”?

Cannot store credit card

Need to ask the 3rd party to help us capture payment information

3rd party give us an idempotent key

Push to queue to handle payment

Inventory reservation

Prompt user to enter payment information -> 3rd party

Another service to process payment information and retries

After payment success, put the success in queue

Update the order and inventory based on payment status

==

Interviewee:

Feels fine with general design

Not familiar with payment

Was hard to find the focus

User experience, did not discuss in detail

Not sure workflow/dividing service is part of the interview, distributed system needs may be more important

Product design, API, micro service, user experience

System design - distributed design, scale up, fault tolerance

How to handle spikes