Scrivio Interview library

Cassandra and DynamoDB

26 questions in 7 subtopics.

Partition keys and clustering columns

ConceptFoundations6 min read
In Cassandra, explain this table's primary key:
CREATE TABLE messages (chat_id uuid, sent_at timeuuid, sender text, body text, PRIMARY KEY ((chat_id), sent_at)) WITH CLUSTERING
ORDER BY (sent_at DESC);
Which queries are efficient and which are not allowed without ALLOW FILTERING?
DesignIntermediate6 min read
An IoT system stores readings per device in Cassandra with PRIMARY KEY ((device_id), ts). Some devices send a reading every second for years, and reads time out on those partitions. Redesign the key and explain how queries change.
ScenarioAdvanced7 min read
A Cassandra cluster of 24 nodes shows one node at 90 percent CPU and disk, while others are at 30 percent. nodetool tablehistograms shows a few huge partitions. How would you investigate and fix this without downtime?
DesignPrincipal6 min read
Cassandra's design comes from Dynamo-style partitioning and Bigtable-style storage. How has that history shaped the data modeling rules engineers must follow, and what does it mean for choosing it today versus newer distributed databases?

Query-first modeling

ConceptFoundations6 min read
Why do Cassandra and DynamoDB models start from the queries rather than from entities and normalisation? Give an example of one entity stored in two tables to serve two queries.
DesignIntermediate7 min read
Design Cassandra tables for an order service that must support: get order by id; list a customer's orders newest first with paging; list orders by status for one warehouse per day. Write the CREATE TABLE statements and explain the write path.
DesignAdvanced7 min read
A product team using DynamoDB now needs ad hoc analytics across all orders (revenue by region, cohort reports). How do you provide this without harming the operational table?
LeadershipPrincipal5 min read
Your company adopted Cassandra years ago for scale, and many teams struggle with query-first modeling, leading to repeated rewrites when product needs change. Today, PostgreSQL with partitioning, distributed SQL and managed NoSQL are all options. How would you set the strategy for operational databases?

Tunable consistency

ConceptFoundations6 min read
Explain Cassandra consistency levels ONE, QUORUM, LOCAL_QUORUM and ALL with a replication factor of 3. When are reads guaranteed to see the latest write?
ScenarioIntermediate6 min read
A Spring Boot service using the DataStax Java driver writes with LOCAL_ONE for speed. Users sometimes do not see their own updates after refreshing, and a few updates seem lost after node restarts. Explain and fix the consistency settings.
DesignAdvanced7 min read
A global product must run in three regions with DynamoDB global tables or Cassandra multi-DC. Some data (user profiles) can be eventually consistent; other data (account balances) must not lose updates. Design the consistency approach for each.
LeadershipPrincipal5 min read
Choosing between availability and consistency used to be a database feature choice. Now businesses want both global reach and correctness. How would you explain these trade-offs to executives and set a company-wide approach?

Tombstones

ConceptFoundations6 min read
What is a tombstone in Cassandra, when is one created, and why does deleting data not free space immediately? What does gc_grace_seconds control?
DebuggingIntermediate6 min read
Reads on a Cassandra table used as a work queue fail with 'Scanned over 100001 tombstones' (TombstoneOverwhelmingException). The application inserts jobs and deletes each one after processing. Explain the cause and redesign it.
ScenarioAdvanced7 min read
After a data center outage of two weeks, a Cassandra cluster with gc_grace_seconds of 10 days is brought back. Soon customers see records reappear that were deleted during the outage. Explain what happened and how you would have prevented it.

DynamoDB keys and secondary indexes

ConceptFoundations7 min read
Explain DynamoDB partition keys and sort keys, and the difference between a global secondary index (GSI) and a local secondary index (LSI). Which reads can be strongly consistent?
CodingIntermediate6 min read
Using the AWS SDK for Java v2 enhanced client, write the code to query a table Orders with partition key customerId and sort key createdAt, returning the customer's orders from the last 30 days, newest first, 20 per page. Explain pagination.
ScenarioAdvanced6 min read
A DynamoDB table backing a user-facing API needs a new query by email, which is not a key. The table has 2 billion items. A developer proposes a Scan with a filter. What would you do instead, and how would you roll it out safely?
LeadershipPrincipal5 min read
DynamoDB offers speed and low operations, but ties the company deeply to one cloud provider. Your board asks about exit risk. How would you assess and manage the lock-in for systems built on DynamoDB?

Hot partitions

ConceptFoundations6 min read
What is a hot partition in DynamoDB or Cassandra, and what symptoms would you see? Give two key designs that cause one.
DesignIntermediate6 min read
A leaderboard for a live game event writes 50,000 score updates per second to one DynamoDB item per event (partition key event_id). The table throttles heavily. Redesign it.
LeadershipAdvanced6 min read
Your multi-tenant platform stores all tenants' data in shared DynamoDB tables keyed by tenant. One very large customer is about to join with ten times the traffic of all others combined. What risks do you raise and what plan do you propose?
DesignPrincipal6 min read
Looking at your company's growth plans, traffic is expected to grow 20 times over five years, with strong seasonal spikes. How would you shape your NoSQL data and capacity strategy so that hot keys and throttling do not become a growth limit?

Single-table design

ConceptFoundations5 min read
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?
DesignIntermediate6 min read
Explain DynamoDB single-table design with an example: store customers, orders and order items in one table so that 'get customer with recent orders' and 'get order with items' are each one Query. Show the key layout.
LeadershipAdvanced5 min read
Half of your teams use single-table design in DynamoDB, the other half use one table per entity, and engineers argue about it in every review. How would you settle it as the principal engineer?