Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

amazon web services - Will DynamoDB API BatchWriteItem always write to the table in the order of the PutRequests in RequestItems?

Simple example for clarification: The JSON below is sent to DynamoDB using BatchWriteItem. Will it always be processed in the exact same order? I must have "Message one" written to the table first, then "Message Two" second, and "Message Three" third.

"RequestItems": {
  "TABLE": [
    {
      "PutRequest": {
        "Item": {
          "Message": {
            "S": "Message one."
          },
          "ID": {
            "S": "S103"
          }
        }
      }
    },
    {
      "PutRequest": {
        "Item": {
          "Message": {
            "S": "Message two."
          },
          "ID": {
            "S": "S104"
          }
        }
      }
    },
    {
      "PutRequest": {
        "Item": {
          "Message": {
            "S": "Message three."
          },
          "ID": {
            "S": "S105"
          }
        }
      }
    },
  ]
}
question from:https://stackoverflow.com/questions/66053237/will-dynamodb-api-batchwriteitem-always-write-to-the-table-in-the-order-of-the-p

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't see anything in the DynamoDB docs that suggest there is an ordering guarantee when using BatchWriteItem. However, the docs do say

The individual PutItem and DeleteItem operations specified in BatchWriteItem are atomic; however BatchWriteItem as a whole is not. If any requested operations fail because the table's provisioned throughput is exceeded or an internal processing failure occurs, the failed operations are returned in the UnprocessedItems response parameter. You can investigate and optionally resend the requests. Typically, you would call BatchWriteItem in a loop. Each iteration would check for unprocessed items and submit a new BatchWriteItem request with those unprocessed items until all items have been processed.

The very idea that some of the requests may end up as unprocessed suggests that order is not guaranteed.

I don't have specific knowledge about how BatchWriteItem ordering is or isn't handled, but wanted to point this out in the event your use case can't handle that uncertainty.

If order is important, you could just fire off multiple requests in-order.

If you're able to share more about the details of your use-case, I'm sure the community could make recommendations that directly address the problem you're trying to solve.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...