Quick revision
The short answer
Cassandra and DynamoDB have no joins and can only query efficiently by key, so a table is useful only if its key matches the question we want to ask. That is why we list the queries first and design one table per query, duplicating data on purpose, because storage is cheap and scatter-gather reads across the cluster are not. For example, a user is stored in users_by_id for profile lookups and in users_by_email for login, and the application writes both, optionally in a Cassandra logged batch so both writes eventually apply together.
What to remember
In this answer, we saw that key-based stores find data only by partition key and offer no joins, so the queries must shape the tables. We duplicated a user into users_by_id and users_by_email, wrote both with a logged batch for eventual atomicity, at the cost of an extra write and no isolation, and described listing access patterns with filters, sort order and volume before designing any key.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Cassandra and DynamoDB have no joins and can only query efficiently by key, so a table is useful only if its key matches the question we want to ask. That is why we list the queries first and design one table per query, duplicating data on purpose, because storage is cheap and scatter-gather reads across the cluster are not. For example, a user is stored in users_by_id for profile lookups and in users_by_email for login, and the application writes both, optionally in a Cassandra logged batch so both writes eventually apply together.
Why this question is asked
Most of us learned data modeling with relational databases: find the entities, normalise them so each fact is stored once, and let the database join them at query time. Bringing that habit to Cassandra or DynamoDB produces tables that cannot answer the application's questions without scanning everything. Interviewers ask this to check that we understand the reason for query-first design, not just the slogan. In this answer, we will see why key-based stores push us toward queries, how denormalisation pays for itself, walk through the users example in CQL and Java, look at keeping the copies in step, and describe the process for listing access patterns.
1Why Entities and Normalisation Do Not Work Here
In a relational database, normalisation works because the database can find rows by any column through indexes and can combine tables with joins. We can design the schema first and think about queries later, since almost any query is possible with the right index.
Cassandra and DynamoDB are different. They place data by its partition key, a hash that decides which nodes store it, and they find data quickly only when we give that key. They have no joins, and a query on a column that is not part of the key would have to read every partition on every node. So a normalised users table keyed by user_id can answer find user 42 instantly, but find the user with this email becomes a full scan. The schema decides which questions are cheap, so we must know the questions first.
2Denormalisation on Purpose
The answer is to store the same data more than once, each copy keyed for a different query. In a relational database, duplication is a smell, because the copies can disagree. Here it is the design, because a duplicated row costs a few hundred bytes of cheap disk, while the alternative, a query that fans out to all nodes, costs latency and cluster capacity on every request and gets worse as data grows.
So the trade-off is explicit: we pay with storage and extra writes, which these databases handle very well, to make every read a single-partition lookup.
3One User, Two Tables
Let us model a user service that needs two queries: load a profile by user id, and find a user by email at login.
| Table | Partition key | Serves | Columns kept |
|---|---|---|---|
| users_by_id | user_id | Profile page | email, name, created_at |
| users_by_email | Login | user_id, name, password_hash |
Notice that each table carries the columns its query needs, not necessarily all columns. users_by_email holds what login needs, including the password hash, so login is one read. The profile page reads users_by_id. The third query shows what we avoid: asking a table for something its key does not cover.
4Writing Both Tables
The application, not the database, keeps the copies together. On registration it inserts into both tables. In Cassandra, a logged batch guarantees that if any statement in it is applied, all of them eventually will be, even if the coordinator fails partway, because the batch is first written to a batch log on other nodes.
The batch is not free: the batch log adds an extra write and round trip, and the two rows live in different partitions on different nodes, so a logged batch is slower than two independent inserts. It also gives atomicity, not isolation: a reader can briefly see one row before the other. For a registration, which is rare, the cost is fine. For high-volume writes, many teams instead write each table independently with retries, or publish an event and let consumers update each table idempotently. In DynamoDB the equivalent is TransactWriteItems, or a global secondary index on email, which DynamoDB maintains for us asynchronously.
5Listing Access Patterns First
In practice, query-first design starts with a document, not a CREATE TABLE. For each screen or API we write down the query in plain words, its filters, its sort order, how many rows it returns, and how often it runs. For example: find user by email, exact match, one row, 200 per second at peak; list a user's last 20 orders, newest first, 50 per second.
From that list we design keys: the equality filters become the partition key, the sort order becomes clustering columns, and the volume tells us whether partitions stay bounded. Notice that a new feature with a new query means a new table and a backfill, which is the real cost of this approach, and why it fits best where queries are stable.
- List each queryFilters, sort, rows returned, rate
- Equality filters -> partition keye.g. email
- Sort order -> clustering columnse.g. created_at DESC
- Partitions bounded?Rows and bytes per partitionYesCreate the tableNoAdd a bucket to the key
- Decide how copies stay in stepBatch, retries or events
5 steps in order. Play them, or step through them one at a time.
6Follow-up questions
What is the cost of updating duplicated data later?
Every copy must be changed. If Maya changes her name, the application updates the row in users_by_id and in users_by_email, and in any other table that stored her name. If the duplicated column is part of a key, such as her email, it is worse: we must delete the old users_by_email row and insert a new one, because a primary key cannot be updated. A missed copy shows stale data, so teams keep duplicated mutable columns to a minimum, store only an id where a value changes often, and route updates through one service that knows every table.
Why not use a secondary index on email instead?
In Cassandra, a classic secondary index is local to each node, so a lookup by email still asks many nodes; for a high-cardinality column like email that is inefficient. Newer storage-attached indexes improve this, so check your version, but for a login query that runs constantly a dedicated table remains the predictable choice. In DynamoDB, a global secondary index is a good fit because it is really a second table maintained by the service.
Does query-first mean no entity design at all?
No. We still understand the entities and their relationships; we just do not let them dictate the tables. The entity model tells us what data exists, and the query list tells us how to lay it out.
7Conclusion
In this answer, we saw that key-based stores find data only by partition key and offer no joins, so the queries must shape the tables. We duplicated a user into users_by_id and users_by_email, wrote both with a logged batch for eventual atomicity, at the cost of an extra write and no isolation, and described listing access patterns with filters, sort order and volume before designing any key.
Open with
Cassandra and DynamoDB locate data by hashing the partition key, and they only query efficiently when you give that key. There are no joins, and filtering on any other column means reading every partition on every node.
Then, if they want more
So unlike a relational design, where I normalise first and add indexes later, the table structure decides which questions are cheap, and I have to start from the queries.
Each access pattern gets a table or index whose key matches it, and data is duplicated on purpose, because disk is cheap and a scatter-gather read is expensive and gets worse as data grows.
For example, for a user service I would create users_by_id with user_id as the primary key for profile lookups, and users_by_email with email as the primary key for login, holding the user id and password hash. The application writes both on registration.
In Cassandra I can put both inserts in a logged batch, which guarantees that both will eventually apply, though it costs an extra write and gives no isolation. For higher volumes I might use independent writes with retries or events.
The process starts by listing access patterns with their filters, sort order, size and rate, then turning equality filters into partition keys and sort orders into clustering columns. The price is that updating duplicated data means changing every copy.
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.
- Official documentation
- Apache Cassandra documentation, Amazon DynamoDB developer guide
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 "Why do Cassandra and DynamoDB models start from the queries rather than from entities...": https://scrivio-interview-library.netlify.app/databases/cassandra-and-dynamodb/d9c48f01a1/