You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Kinesis中Partition Key(分区键)是什么?其后台机制解析

Understanding AWS Kinesis Partition Keys (With Your Scenario Explained)

Great question—official docs can feel overly technical, so let’s break this down with your exact use case in mind.

What is a Partition Key?

At its core, a Partition Key is a routing label you assign to each Kinesis record. It’s how Kinesis decides which shard (the underlying storage/processing unit of a Kinesis stream) to send your record to.

Think of shards as separate buckets: the Partition Key acts like a label that tells Kinesis, "Put this record in bucket X, not bucket Y." It uses a hash function on the Partition Key to map it to a specific shard—same key = same hash = same shard every time.

What Happened Behind the Scenes in Your Test?

You ran this code 10 times with the same PartitionKey: 'TestKey_1':

var params = { 
  Data: 'More Sample data into the test stream ...', 
  PartitionKey: 'TestKey_1', 
  StreamName: 'TestStream' 
};
kinesis.putRecord(params, function(err, data) { 
  if (err) console.log(err, err.stack); 
  else console.log(data); 
});

Here’s what Kinesis did each time:

  • It calculated a hash value for TestKey_1.
  • Mapped that hash to one specific shard in your TestStream.
  • Added each new record in the exact order you sent them to that same shard.

Key outcomes from this:

  • All 10 records live in the same shard (check the ShardId in your console.log(data) output—they’ll all match!).
  • Kinesis guarantees that records with the same Partition Key are processed in the order they were received. If you later consume these records, they’ll show up in the sequence you inserted them.

Why Does This Matter?

Partition Keys serve two big purposes:

  1. Order Guarantees: If you need related records (e.g., all actions from a single user, or steps in a workflow) to stay in order, use the same Partition Key—they’ll stick to one shard, where order is preserved.
  2. Throughput Scaling: If you use different Partition Keys, Kinesis spreads records across multiple shards. Each shard supports a fixed throughput (1MB/s ingest, 2MB/s egress), so more shards mean more parallel processing capacity.

In your test, since you used the same key, you didn’t leverage parallelism—but you did ensure your 10 records stayed in sequence.

内容的提问来源于stack exchange,提问作者Suhail Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:06:49