Scrivio Interview library
ConceptFoundations5 min read · updated 12 November 2026

In a DynamoDB single-table design, what is a GSI overloading pattern, and why do teams name key attributes PK, SK, GSI1PK and GSI1SK instead of customerId or orderId?

GSI overloading means one global secondary index serves several access patterns, because each entity type writes different kinds of values into the same index key attributes, for example STATUS#OPEN for orders and EMAIL#x for customers. Teams name the attributes PK, SK, GSI1PK and GSI1SK instead of customerId or orderId because a generic name can hold a different meaning for each entity type in one table. This keeps the number of indexes low, which saves write cost and stays within quotas, at the price of readability, so the key values must be documented and built in one place in code.

Why this question is asked

Single-table design is a style of DynamoDB modelling in which many entity types share one table. People meeting it for the first time are puzzled by tables full of attributes called PK and SK with values like CUSTOMER#123. Interviewers ask about GSI overloading to see whether we understand why the style looks that way and what it costs. In this answer, we will recap what a GSI costs, see why generic key names exist, walk through an overloaded index with an example, and look at how to keep such a design understandable.

1A Quick Recap of What a GSI Costs

A global secondary index (GSI) is a copy of selected attributes of the table, arranged under its own partition key and sort key, so we can query by something other than the primary key. DynamoDB keeps it updated: every write to an item that has the index's key attributes is also written to the index.

So each GSI adds write cost, roughly one more write per indexed item change, plus storage for the projected attributes. In provisioned mode it also has its own capacity to manage, and an under-provisioned GSI throttles writes to the whole table. A table has a quota of 20 GSIs by default. If every new access pattern got its own index, a table serving six entity types could hit that quota and would pay for many indexes on every write.

2Why Keys Get Generic Names

In a single-table design, a customer, an order and an order item live in the same table. Their primary keys mean different things: for a customer the partition key is a customer id, for an order item it might be the order id. If the attribute were called customerId, it would be wrong for order items. So the table uses neutral names, PK and SK, and each entity type decides what goes in them. A prefix in the value, like CUSTOMER# or ORDER#, says what kind of key it is and keeps different entity types from colliding.

The same reasoning applies to indexes. An index whose key attributes are called GSI1PK and GSI1SK does not commit to one meaning. Each entity type can put its own kind of value there, and that is what makes overloading possible.

3An Overloaded Index in Practice

Suppose we need two lookups that nothing else serves: 'all open orders, oldest first' for a fulfilment screen, and 'find a customer by email' for login. Without overloading we would create two GSIs. With overloading, both use GSI1.

Items and their GSI1 keys
EntityPK / SKGSI1PKGSI1SK
CustomerCUSTOMER#123 / PROFILEEMAIL#ana@example.comCUSTOMER#123
CustomerCUSTOMER#456 / PROFILEEMAIL#raj@example.comCUSTOMER#456
Order (open)CUSTOMER#123 / ORDER#987STATUS#OPEN2026-11-01T10:00:00Z
Order (open)CUSTOMER#456 / ORDER#990STATUS#OPEN2026-11-02T08:15:00Z
Order itemORDER#987 / ITEM#001(not set)(not set)
Each entity type writes its own kind of value into GSI1PK; items without it stay out of the index.

Both queries are a plain Query on GSI1. The email lookup asks for GSI1PK = 'EMAIL#ana@example.com' and gets one customer. The fulfilment screen asks for GSI1PK = 'STATUS#OPEN' and gets open orders ordered by GSI1SK, the creation time. Order items never set GSI1PK, so they are not in the index at all. That is called a sparse index, and it keeps the index small.

4Writing the Keys in Code

The trade-off is that nobody can read the table and know what GSI1PK means without context. The remedy is discipline: build all key values in one place, so the meaning lives in code and documentation, not in people's heads.

Java
final class Keys {
static String customerPk(String id) { return "CUSTOMER#" + id; } // CUSTOMER#123
static String emailGsi1(String email) { return "EMAIL#" + email.toLowerCase(Locale.ROOT); }
static String statusGsi1(String s) { return "STATUS#" + s; } // STATUS#OPEN
}
Map<String, AttributeValue> order = Map.of(
"PK", AttributeValue.fromS(Keys.customerPk("123")),
"SK", AttributeValue.fromS("ORDER#987"),
"type", AttributeValue.fromS("Order"),
"GSI1PK", AttributeValue.fromS(Keys.statusGsi1("OPEN")),
"GSI1SK", AttributeValue.fromS("2026-11-01T10:00:00Z"));
// When the order ships, the code removes GSI1PK and GSI1SK, so it leaves the open-orders index.

Notice the type attribute. Because one query can return different entity types, each item records what it is, so the mapping code can turn it into the right class. Alongside the code, a short access-pattern document lists every pattern, the index it uses and the exact key format, such as 'GSI1: EMAIL#lowercase email -> customer; STATUS#status -> orders by creation time'.

5When Overloading Is Worth It

Overloading pays off when a table has several entity types and many access patterns, and when write cost and index count matter. It is not always the right call. A STATUS#OPEN partition holds every open order, so at high volume it becomes a hot partition and needs sharding, such as STATUS#OPEN#07. And if two patterns need very different projections, separate indexes may be cheaper because each projects only what its query returns. The goal is fewer indexes where it is natural, not a puzzle.

6Follow-up questions

Is GSI overloading only useful in single-table design?

Mostly, because it relies on different entity types sharing index attributes. In a table with one entity type, we can still put different kinds of values in a generic GSI attribute, but the benefit is smaller.

Can we query 'customers by email' and 'orders by status' with one request?

No. Each Query takes one GSI1PK value, so these are separate requests on the same index. Overloading saves indexes, not requests.

How do we stop someone writing a wrong key format?

Build keys only through one key-building module, cover it with tests, and review changes to it carefully. Some teams also validate item shapes in a repository layer before writing.

7Conclusion

In this answer, we saw that every GSI adds write cost, storage and a quota slot, so single-table designs reuse indexes. Generic attribute names like PK, SK, GSI1PK and GSI1SK let each entity type store its own kind of value, which lets one overloaded index serve customer lookup by email and open orders by status. The cost is readability, so keys are built in one module, items carry a type attribute, and an access-pattern document records every key format.

What to say in the interviewAbout 90 seconds aloud

Open with

In single-table design, several entity types live in one table, so a key attribute cannot be called customerId, because for an order item it would hold an order id.

Then, if they want more

Teams use generic names like PK and SK, and each entity type puts its own value in them with a prefix, like CUSTOMER#123 or ORDER#987. GSI overloading applies the same idea to indexes. The index keys are called GSI1PK and GSI1SK, and different entity types write different kinds of values into them, so one GSI serves several access patterns.

For example, open orders write GSI1PK equals STATUS#OPEN with the creation time as sort key, which serves an open-orders query, while customers write GSI1PK equals EMAIL# plus their address, which serves login by email. Items that set neither, like order items, stay out of the index, so it is sparse.

The reason to do this is that each GSI adds write cost and storage, needs capacity in provisioned mode, and counts against a quota of twenty per table, so keeping the number of indexes low matters. The price is readability: you cannot tell from the table what GSI1PK means.

So I would build all key values in one place in code, store a type attribute on each item, and keep a document listing every access pattern and its key format.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "In a DynamoDB single-table design, what is a GSI overloading pattern, and why do teams...": https://scrivio-interview-library.netlify.app/databases/cassandra-and-dynamodb/2e80e9c08d/