Skip to content

Per-partition throttling takes the first attribute of Key or Item as the partition key #779

In review

Description

@LeeroyHannigan

Per-partition throttling chooses an item's bucket by the first attribute in Key or Item, which is not always the partition key.

extract_partition_value in crates/server/src/throttle_helpers.rs (lines 101 to 118 on main at 82445c5) returns the value of the first member of Key for GetItem, DeleteItem and UpdateItem, and of Item for PutItem. Its comment says DynamoDB key maps are ordered. They are not, and the parsed request body is sorted by attribute name on the SQLite, PostgreSQL and Cassandra builds; the fix for #723 sorts it on the MongoDB build too.

So a PutItem of {"pk": {"S": "user-1"}, "data": {"S": "x"}} is counted against the bucket for x, because data sorts before pk. Items whose first attribute in name order holds the same value share one bucket whatever their partition key, and a first attribute of a type other than S, N or B (a map, a list, a set, BOOL or NULL) gives the empty string, so all such items share one bucket.

Expected: read the partition key's name from the table's key schema and take that attribute's value.

Activity

  1. added
    bug
    on Nov 3, 2026
  2. LeeroyHannigan commented on Nov 23, 2026

    @LeeroyHannigan
    CollaboratorAuthor

    Measured on a SQLite server: a release build of #398's branch with main merged, throttling_enabled true, 23 Nov 2026. The partition buckets refill at 1,000 WCU and 3,000 RCU a second and start with one second of capacity.

    • PutItem of 390,000-byte items, 381 WCU each, on a table keyed by pk. Ten items with one pk and a different a each, in 73 ms: all ten got 200. A bucket keyed by pk would refuse the fourth. Ten items with a different pk each and one a: three got 200, then seven got 400 ProvisionedThroughputExceededException. The bucket follows a, the first attribute by name.
    • Strongly consistent GetItem of 390,000-byte items, 96 RCU each, on a table with partition key zpk and sort key ask. 100 reads of one zpk over ten ask values, in 434 ms: all 100 got 200. 100 reads of ten zpk values with one ask: from the 41st read on, 57 got 400. The bucket follows ask, the sort key, because it sorts before zpk.

    Every request sent the partition key first in the JSON. #1377 and #1381 change how extract_partition_value reads the value and keep the first attribute.

  3. self-assigned this
    on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions