0
0
DynamoDBquery~5 mins

Table capacity modes (on-demand vs provisioned) in DynamoDB - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Table capacity modes (on-demand vs provisioned)
O(1)
Understanding Time Complexity

When using DynamoDB, how fast your requests run depends on the table's capacity mode.

We want to understand how the choice between on-demand and provisioned modes affects request speed as data grows.

Scenario Under Consideration

Analyze the time complexity of reading an item from a DynamoDB table in different capacity modes.


// Read item from DynamoDB table
const params = {
  TableName: "MyTable",
  Key: { "id": "123" }
};
const result = await dynamodb.getItem(params).promise();
return result.Item;
    

This code fetches one item by its key from a DynamoDB table.

Identify Repeating Operations

Look for repeated steps that affect speed.

  • Primary operation: Single key lookup in the table.
  • How many times: Once per request; no loops or recursion here.
How Execution Grows With Input

As the table grows, how does the time to get one item change?

Input Size (n)Approx. Operations
10 items1 lookup operation
1,000 items1 lookup operation
1,000,000 items1 lookup operation

Pattern observation: The time to get one item stays about the same no matter how big the table is.

Final Time Complexity

Time Complexity: O(1)

This means fetching one item takes about the same time regardless of table size.

Common Mistake

[X] Wrong: "On-demand mode is slower because it handles more requests automatically."

[OK] Correct: Both on-demand and provisioned modes use the same fast key lookup; the difference is in how capacity is managed, not speed per request.

Interview Connect

Knowing how DynamoDB handles capacity helps you explain performance choices clearly and shows you understand cloud database behavior.

Self-Check

"What if we changed the query to scan the whole table instead of a key lookup? How would the time complexity change?"