Cassandra and DynamoDB
26 questions in 7 subtopics.
Partition keys and clustering columns
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);
Query-first modeling
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.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.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?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
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?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.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.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
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?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.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
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?Using the AWS SDK for Java v2 enhanced client, write the code to query a table Orders with partition keycustomerId and sort key createdAt, returning the customer's orders from the last 30 days, newest first, 20 per page. Explain pagination.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?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
What is a hot partition in DynamoDB or Cassandra, and what symptoms would you see? Give two key designs that cause one.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.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?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
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 ofcustomerId or orderId?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.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?No question matches these choices.