简体   繁体   中英

DynamoDB Schema Design - Order Model

I am modeling a simple application an I would like to use DynamoDB as my storage. I need to store a all order from a ecommerce website. It is possible to query using the order_id and the user email.

Looking at the dynamodb documentation, I think the best approach is to user the order_id (Most of my queries will be made on this index) as my primary key (Partition key).

And what about email? I would like a secondary index, but I am bit lost. What is the best approach?

It looks like a Global Secondary Index on the email attribute would solve the problem:

  • when you need to lookup by order_id , you use the GetItem operation and specify that order_id as the primary key

  • when you need to lookup by email , you use the Query API on the GSI and specify the email as the partition key.

GSI have independent read capacity units - since you said you will use order_id most of the time, you could provision more RCU to the main table than the GSI.

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM