0
0
DynamodbConceptBeginner · 3 min read

What is Write Capacity Unit in DynamoDB: Simple Explanation

A Write Capacity Unit (WCU) in DynamoDB represents one write per second for an item up to 1 KB in size. If your item is larger than 1 KB, DynamoDB consumes additional WCUs proportionally. It helps control and measure the write throughput capacity of your database table.
⚙️

How It Works

Think of a Write Capacity Unit (WCU) as a ticket that lets you write one small item (up to 1 KB) into your DynamoDB table each second. If your item is bigger, you need more tickets. For example, writing a 3 KB item uses 3 WCUs because it’s like handing over three 1 KB chunks.

This system helps DynamoDB manage how much writing your table can handle at once. You buy a certain number of WCUs when you create or update your table, and DynamoDB uses them to limit how many writes happen per second. If you try to write more than your WCUs allow, your writes might slow down or get throttled.

It’s like having a water pipe with a fixed size: the WCUs control how much water (write data) can flow through per second. If you want more water, you need a bigger pipe (more WCUs).

💻

Example

This example shows how to specify write capacity units when creating a DynamoDB table using AWS SDK for Python (boto3). It sets the write capacity to 5 WCUs, meaning the table can handle 5 writes per second for items up to 1 KB each.

python
import boto3

dynamodb = boto3.resource('dynamodb')

table = dynamodb.create_table(
    TableName='ExampleTable',
    KeySchema=[
        {'AttributeName': 'id', 'KeyType': 'HASH'}
    ],
    AttributeDefinitions=[
        {'AttributeName': 'id', 'AttributeType': 'S'}
    ],
    ProvisionedThroughput={
        'ReadCapacityUnits': 5,
        'WriteCapacityUnits': 5
    }
)

table.wait_until_exists()
print(f"Table {table.table_name} created with 5 WCUs.")
Output
Table ExampleTable created with 5 WCUs.
🎯

When to Use

You use Write Capacity Units when you want to control how many writes your DynamoDB table can handle per second. This is important for managing costs and performance.

For example, if you expect your app to write 100 small items per second, you should set your WCUs to at least 100. If your items are larger, increase WCUs accordingly.

Use WCUs in scenarios like:

  • High-traffic apps that write data frequently, like social media posts or sensor data.
  • When you want predictable billing and performance by provisioning capacity.
  • When using DynamoDB’s provisioned capacity mode instead of on-demand mode.

Key Points

  • One WCU allows one write per second for an item up to 1 KB.
  • Items larger than 1 KB consume more WCUs proportionally.
  • WCUs help control write throughput and cost.
  • Provision WCUs based on your app’s expected write traffic.
  • Exceeding WCUs causes throttling and slower writes.

Key Takeaways

A Write Capacity Unit (WCU) equals one write per second for a 1 KB item in DynamoDB.
Larger items consume more WCUs, so plan capacity based on item size and write frequency.
Provision WCUs to control write throughput and avoid throttling.
Use WCUs in provisioned capacity mode for predictable performance and cost.
Monitor and adjust WCUs as your app’s write needs change.