A composite key is a key made from two or more attributes, such as (tenant_id, order_number). If that pair is the primary key, two tenants can use the same order number, and one tenant can have many orders, but the same pair cannot identify two records. A composite secondary index also uses multiple attributes, but it does not enforce uniqueness unless the database supports that constraint and the index is defined as unique. An attribute can be a key component in one index and ordinary record data elsewhere.
Design the key around the application's most important reads and writes. In a store with a partition-and-sort key model, using tenant_id as the partition key and order_number as the sort key lets the application fetch one order with both values or query a range of order numbers for a specific tenant. In a relational database, a B-tree index on the same pair typically supports efficient lookups by tenant alone or by tenant and order number. An order-number-only lookup generally needs a different index for predictable performance. The uniqueness rule is the same if the pair is reversed, but the access paths can change substantially.
In a distributed store, evaluate the cardinality and traffic distribution of the partitioning attributes, not just the uniqueness of the full composite key. Millions of unique order numbers do not spread writes if most orders belong to one tenant and the store routes by tenant_id. A high-cardinality partition key gives the store more values across which to spread traffic, but it does not prevent a popular value from becoming hot. For a very busy tenant, adding a shard suffix to the partitioning value can spread writes, at the cost of querying multiple shards and merging results for a tenant-wide read.
Distinguish a key-based query from a scan with a filter. A key-based query uses the key structure to narrow what the database reads; a scan can read many records and discard nonmatching ones afterward. If an application frequently lists orders by creation time but the primary key uses order number, an alternate index on (tenant_id, created_at, order_number) can support time ranges and provide a deterministic order for records with the same timestamp. That index adds storage and write work. It may also offer different read consistency from the base table: where an index is updated asynchronously, a query can temporarily omit a recent write even when a strongly consistent base-table lookup would see it. Choose a read path that meets the application's freshness requirements as well as its lookup pattern.
Prefer native multi-attribute keys when they fit the access pattern. If a store exposes a single key field and the application encodes several values into it, define a collision-free encoding and verify that its sort order matches the intended queries. For example, plain text places 10 before 2 in lexicographic order, so a numeric range requires an order-preserving representation. Choose stable identity attributes when possible: changing a primary-key component may require moving or rewriting a record, and in a relational design every foreign key that references the composite key must carry all of its components.