skip to Main Content

I know that when executing a get request, dynamodb would leverage the partition key to determine what partition the row is in. But, my question: what happens next? The docs say that if you have specified a sort key, then data within the partition would be sorted which means quick lookup. But let’s say if I haven’t specified a sort key. What happens next? I’d imagine it’s either one of the following but not sure which one is it:

  1. there’s a separate lookup (ie O(1) operation) happening (again using partitionKey) within the partition. I’m not sure what hash function would be used here and how it would (or even could) be any different than the previous hash function.

  2. DynamoDb scans through the data within the partition until it finds the row matching partitionKey (which seems painful). I’d pray that data would at least be sorted within partition by partition key else this seems like O(n) operation to me. A scan would conflict with popular opinion that DynamoDB is fast for all use cases (with single digit milliseconds latency).

I’m not seeing any docs around this specific case so would love to hear from DynamoDB experts here. Links would be appreciated.

Thanks in advance

2

Answers


  1. DynamoDB requests are interpreted by a component called RequestRouter which contains a local cache of which partition your item exists.

    1. Request hits front end fleet
    2. Request hits RequestRouter
    3. Partition key is hashed, local cache is searched for the location of the item O(1)
    4. Items within a Partition are ordered by the hash of the partition key, then each collection is ordered by the sort key.
    5. Lookup is O(log n) as the items are in order.
    Login or Signup to reply.
  2. Although not a direct answer, I want to contribute the following AWS video on how DynamoDB works under the hood. This video has taught me a lot in my career for building high throughput applications with DynamoDB. I hope it helps you out as well 🙂

    https://youtu.be/yvBR71D0nAQ

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search