NoSQL for Data Engineers
Cassandra query-first tables, tombstones and tunable consistency as an extract sees them, MongoDB documents flattened into a warehouse, change streams as CDC, schema drift, and HBase row-key hotspots.
10 questions
JuniorTheoryCommonAn orders collection in the document database MongoDB embeds an array of line items — how do you land it in a warehouse?
An orders collection in the document database MongoDB embeds an array of line items — how do you land it in a warehouse?
Split by grain: an orders table with one row per document and an order_items table with one row per array element, keyed by order _id plus position. One flat wide table repeats order fields on every item, so summed order totals inflate.
Common mistakes
- ✗Unwinding the array into one table and then summing order-level amounts such as shipping or discount across its rows
- ✗Keying the child table by the item's position alone, so a reload or a reordered array cannot be matched back to its order
- ✗Leaving the array as a JSON string in the warehouse and parsing it in every report
Follow-up questions
- →The application edits one line item in place — how do you update
order_itemswithout duplicates? - →When would you reference line items from a separate collection instead of embedding them in MongoDB?
JuniorTheoryCommonWhy can't analysts run ad-hoc filters and GROUP BY reports on a table in the wide-column store Cassandra?
Why can't analysts run ad-hoc filters and GROUP BY reports on a table in the wide-column store Cassandra?
A Cassandra table is built for one query: the partition key picks the nodes, clustering columns order rows inside a partition. There are no joins; a filter on another column needs ALLOW FILTERING, a scan of every partition. Analytics runs on an extract.
Common mistakes
- ✗Treating
ALLOW FILTERINGas a harmless switch instead of a scan of every partition in the cluster - ✗Modelling a Cassandra table like a normalised relational table and expecting joins to assemble the report
- ✗Reading 'wide-column' as column-oriented storage, as in an analytical warehouse
Follow-up questions
- →The product team now also needs orders by status — what do you add to the Cassandra schema?
- →How would you copy a whole Cassandra table into the warehouse without any
ALLOW FILTERINGquery?
JuniorTheoryCommonWrites and an extract both use consistency level ONE on Cassandra with replication factor 3 — what can the extract miss?
Writes and an extract both use consistency level ONE on Cassandra with replication factor 3 — what can the extract miss?
A write at ONE is acknowledged by one replica; a read at ONE asks one replica, which may not have it yet, so recent rows and deletes can be missing or stale. Reads see every acknowledged write only when R + W > RF: QUORUM on both sides (2 + 2 > 3).
Open full question →Common mistakes
- ✗Believing ONE still copies the write to every replica before acknowledging it
- ✗Adding up R + W = 3 for QUORUM reads over ONE writes and calling it consistent, when it must exceed RF
- ✗Forgetting that a delete is a write too, so a stale replica can return a row that was already deleted
Follow-up questions
- →With two datacenters, what do LOCAL_QUORUM and LOCAL_ONE change for an extract running in the analytics datacenter?
- →Which Cassandra mechanisms bring a lagging replica up to date, and which of them can an extract rely on?
MiddleDesignCommonA MongoDB collection events is written by three versions of a mobile app and loaded nightly into a typed warehouse table. Old versions send price as a string ("199.00"), new ones as a number, and some events omit it; the nested device object keeps gaining fields. Last week the load failed when price arrived as a string, and the hotfix cast every column to text, which broke the revenue reports. MongoDB has no schema validation on the collection. Constraints: analysts need typed columns, a bad document must not stop the whole load, any day may need to be reloaded, and the app team can change its payload with a week's notice. Design how documents land in the warehouse so that new fields and type changes neither break the load nor silently corrupt reports.
A MongoDB collection events is written by three versions of a mobile app and loaded nightly into a typed warehouse table. Old versions send price as a string ("199.00"), new ones as a number, and some events omit it; the nested device object keeps gaining fields. Last week the load failed when price arrived as a string, and the hotfix cast every column to text, which broke the revenue reports. MongoDB has no schema validation on the collection. Constraints: analysts need typed columns, a bad document must not stop the whole load, any day may need to be reloaded, and the app team can change its payload with a week's notice. Design how documents land in the warehouse so that new fields and type changes neither break the load nor silently corrupt reports.
Land each document unchanged as JSON in a raw layer with its load date, so any day can be reloaded. In staging, cast known fields explicitly, send rows that fail to quarantine with an alert, keep new fields in JSON. Add a contract or $jsonSchema at the source.
Common mistakes
- ✗Casting every column to text so the load never fails, which moves the failure into every report
- ✗Dropping documents that do not fit the table instead of quarantining them for a fix and a reload
- ✗Keeping no raw copy, so a fixed cast cannot be re-applied to the days already loaded
Follow-up questions
- →How would you detect a new field in
devicebefore an analyst asks for it? - →What would a MongoDB
$jsonSchemavalidator withvalidationAction: warngive you, compared witherror?
MiddleDebuggingOccasionalA nightly extract from a delete-heavy Cassandra queue table slows down, then fails — diagnose it from the log
A nightly extract from a delete-heavy Cassandra queue table slows down, then fails — diagnose it from the log
Each DELETE writes a tombstone kept for gc_grace_seconds (10 days) and until compaction, so the one billing partition holds millions and every read scans them: a warning past 1,000, an abort past 100,000. Bucket the key by time; read past the last done row.
Common mistakes
- ✗Thinking a Cassandra
DELETEfrees the row at once, when it adds a tombstone that every read of the range must skip - ✗Raising
tombstone_failure_thresholdinstead of changing the partition design that piles tombstones up - ✗Setting
gc_grace_secondsto 0 on a table with deletes, which lets a replica that missed a delete bring the row back
Follow-up questions
- →How does a TTL row become a tombstone, and what does the compaction strategy
TimeWindowCompactionStrategychange here? - →Why is a queue on Cassandra an anti-pattern, and where would you put this backlog instead?
MiddleDebuggingOccasionalAfter a weekend outage, a MongoDB change-stream loader into the warehouse cannot resume — diagnose and recover
After a weekend outage, a MongoDB change-stream loader into the warehouse cannot resume — diagnose and recover
The token points to Friday 18:00, but the oplog holds only ~20 hours and now starts Sunday 09:41, so the stream cannot resume and gap changes are lost. Open a new stream, keep its token, reload by _id upserts, then replay it; size the oplog past the longest outage.
Common mistakes
- ✗Opening the stream with no resume token and assuming it replays from where the loader stopped, when it starts from now
- ✗Taking the snapshot first and opening the stream afterwards, which loses the changes made while the snapshot ran
- ✗Sizing the oplog in gigabytes without checking how many hours it holds at peak write rate
Follow-up questions
- →Why does the loader save the token only after the batch is written, and what delivery guarantee does that give?
- →How does Debezium's MongoDB connector behave in the same situation under
snapshot.modeinitialandwhen_needed?
MiddlePerformanceOccasionalWhy does a timestamp row key send all writes to one server in the wide-column store HBase, and what key fixes it?
Why does a timestamp row key send all writes to one server in the wide-column store HBase, and what key fixes it?
Rows sort by row key and each region owns a contiguous key range, so a timestamp-led key sends every new write to the last region. Lead with a hashed prefix or a high-cardinality field such as device_id; a time-range scan then reads every prefix.
Common mistakes
- ✗Thinking HBase hashes row keys across servers the way Cassandra hashes partition keys
- ✗Believing a reversed timestamp at the front of the key spreads writes, when it only flips which end of the key space is hot
- ✗Salting the key without planning that every time-range extract must now run one scan per salt value
Follow-up questions
- →How would a nightly Spark job extract one day of events from a table salted into 16 buckets?
- →Where does Google's managed wide-column service Bigtable put the timestamp in a row key, and why?
SeniorDesignOccasionalEvery night a 6 TB Cassandra table events_by_user (replication factor 3) must land in the lake as Parquet on S3. The cluster has two datacenters: prod, which serves the app with a p99 read latency under 20 ms, and analytics, which holds a full replica and serves nobody else. The first attempt ran SELECT * FROM events_by_user ALLOW FILTERING from one Python process with paging: it ran for 14 hours, timed out twice, and the app's p99 doubled while it ran. The app writes at LOCAL_QUORUM in prod. The export must finish within 4 hours, must not affect app latency, and the lake team wants to know how consistent the copy is. Design the export: how the work is split, where and at which consistency level it reads, how load is limited, what consistency the copy has, and when you would copy SSTable snapshots instead.
Every night a 6 TB Cassandra table events_by_user (replication factor 3) must land in the lake as Parquet on S3. The cluster has two datacenters: prod, which serves the app with a p99 read latency under 20 ms, and analytics, which holds a full replica and serves nobody else. The first attempt ran SELECT * FROM events_by_user ALLOW FILTERING from one Python process with paging: it ran for 14 hours, timed out twice, and the app's p99 doubled while it ran. The app writes at LOCAL_QUORUM in prod. The export must finish within 4 hours, must not affect app latency, and the lake team wants to know how consistent the copy is. Design the export: how the work is split, where and at which consistency level it reads, how load is limited, what consistency the copy has, and when you would copy SSTable snapshots instead.
Split the scan by token ranges, read in parallel by the Spark Cassandra Connector, pinned to the analytics DC and throttled per core, at LOCAL_QUORUM (default LOCAL_ONE). No cluster-wide snapshot exists: the copy is fuzzy over the run, so load it idempotently by key.
Common mistakes
- ✗Paging through
ALLOW FILTERINGfrom one client instead of splitting the token ring into parallel range scans - ✗Running the export against the serving datacenter, or against every node, and competing with the application for the same replicas
- ✗Calling the result a snapshot, when each token range is read at a different moment during the run
Follow-up questions
- →How would you turn the nightly full export into an incremental one when the table has no reliable change timestamp?
- →Why can one oversized Cassandra partition still leave a single straggling Spark task?
SeniorDesignOccasionalDesign change data capture from a sharded MongoDB 7.0 cluster into an analytics warehouse. The orders collection holds 3 TB; each order embeds an items array, and the app changes orders with partial updates ($set of the status, $push of an item) and hard deletes. The warehouse needs current-state orders and order_items tables with lag under 5 minutes, and deletes must reach it. An outage of the pipeline of up to 24 hours must not force a full reload, and the initial load must not leave a gap before streaming starts. Explain where the change stream is opened and what ordering it gives, how the pipeline gets the full row when an update event carries only the changed fields, how the initial load hands over to the stream, how deletes and array changes are applied to the two tables, and what you size and monitor on the MongoDB side.
Design change data capture from a sharded MongoDB 7.0 cluster into an analytics warehouse. The orders collection holds 3 TB; each order embeds an items array, and the app changes orders with partial updates ($set of the status, $push of an item) and hard deletes. The warehouse needs current-state orders and order_items tables with lag under 5 minutes, and deletes must reach it. An outage of the pipeline of up to 24 hours must not force a full reload, and the initial load must not leave a gap before streaming starts. Explain where the change stream is opened and what ordering it gives, how the pipeline gets the full row when an update event carries only the changed fields, how the initial load hands over to the stream, how deletes and array changes are applied to the two tables, and what you size and monitor on the MongoDB side.
Open one change stream on mongos (or Debezium's MongoDB connector); record its position, snapshot, replay with _id upserts. Updates carry only deltas: use post-images (6.0+) or full documents; deletes bring only _id. Rebuild an order's items; keep oplog over 24 h.
Common mistakes
- ✗Opening a change stream per shard and losing the cluster-wide ordering that
mongosgives - ✗Assuming an update event carries the whole document, or that
updateLookupreturns the document as it was at the time of the update - ✗Starting the stream after the snapshot ends, which drops the changes made while the snapshot ran
Follow-up questions
- →What does Debezium's MongoDB connector option
capture.modechange in the events the warehouse receives? - →How would you keep a history table of order status changes as well as the current state?
SeniorDebuggingRareCassandra extract counts differ between two runs on one day, and cancelled subscriptions reappear — diagnose from the facts
Cassandra extract counts differ between two runs on one day, and cancelled subscriptions reappear — diagnose from the facts
Writes and reads at ONE need not overlap (1 + 1 < 3), so each run reads whichever replica answers. c3, down 12 days past the 3-hour hint window, missed October's deletes; the others purged those tombstones after 10 days, so c3's rows came back. Re-delete, repair, use QUORUM.
Open full question →Common mistakes
- ✗Trusting hinted handoff to deliver every missed write, when hints stop after
max_hint_window(3 hours by default) - ✗Letting a node that was down longer than
gc_grace_secondsrejoin without wiping and rebuilding it - ✗Shortening
gc_grace_secondsto make tombstones disappear, which makes resurrection more likely, not less
Follow-up questions
- →How would the warehouse catch resurrected rows without trusting Cassandra, for example against a CDC feed?
- →Which repair schedule keeps a table with deletes safe, and how does it relate to
gc_grace_seconds?