nosql_databases 50 Q&As

Nosql Databases FAQ & Answers

50 expert Nosql Databases answers researched from official documentation. Every answer cites authoritative sources you can verify.

unknown

50 questions
A

$lookup performs left outer join to another collection in same database, similar to SQL JOIN. Syntax: {$lookup: {from: 'collection', localField: 'field', foreignField: 'field', as: 'arrayField'}}. Adds matched documents from joined collection as array field in output. Performance considerations (2025): $lookup performs separate collection lookup per document, can be slow on large datasets. Optimization techniques: (1) Index foreign fields for faster lookups (critical), (2) Use $match before $lookup to filter documents and reduce lookups performed, (3) Place $lookup after $limit to limit number of join operations, (4) Use $project to include only necessary fields minimizing memory usage, (5) Consider data denormalization for frequently accessed joins - duplicate rarely-changing data to avoid $lookups. Query optimizer: MongoDB coalesces $unwind and $match into $lookup stage when possible, uses slot-based execution engine for improved performance. Best practice: Structure collections so common queries avoid $lookups when possible. Monitor: Use .explain('executionStats') to identify $lookup bottlenecks and verify index usage on foreign collection.

99% confidence
A

Compound indexes index multiple fields to optimize queries filtering on multiple criteria. Created with db.collection.createIndex({field1: 1, field2: 1}); - supports queries on field1 or {field1, field2} (left-to-right prefix matching). Multikey indexes handle array-containing fields, automatically created when indexing arrays. MongoDB creates separate index entries for each array element. Example: {tags: ['a', 'b']} creates 2 index entries. Compound multikey restriction: At most one indexed field per document can be an array. Valid: {tags: ['a', 'b'], category: 'x'} with index {tags: 1, category: 1}. Invalid: {tags: ['a'], sizes: ['S', 'M']} with same compound index (rejected on insert). ESR guideline (2025): Order compound index fields as Equality, Sort, Range for optimal performance. Best practice: Prefer single compound indexes over multiple single-field indexes - faster than index intersection. Monitor with db.collection.explain('executionStats') to verify index usage.

99% confidence
A

Primary key = Partition Key + Clustering Columns (optional). Syntax: PRIMARY KEY ((partition_key), clustering_col1, clustering_col2). Partition key determines which node stores data via consistent hashing - partition key value → hash → token → specific node. Distributes data evenly across cluster nodes. Clustering key sorts data within partition, ordering rows with same partition key value. Example: PRIMARY KEY ((user_id), timestamp, event_type) - user_id distributes across nodes, data sorted by timestamp then event_type within each partition. Composite partition keys: ((col1, col2)) increases cardinality for better distribution. Query requirements (2025): Partition key required in WHERE clause (targeted reads), clustering columns optional for range queries within partition. Queries without partition key trigger expensive full-cluster scans. Good partition key characteristics: High cardinality (many unique values), evenly distributed values, matches query access patterns. Monitor distribution: nodetool status checks data balance across nodes.

99% confidence
A

GSI (Global Secondary Index): Different partition/sort keys from base table, queries span all partitions globally, separate provisioned throughput, eventual consistency only (single-digit millisecond propagation lag typical), no size limit, can be created/deleted anytime. LSI (Local Secondary Index): Same partition key as base table with different sort key, scoped to single partition, shares table throughput, supports strong or eventual consistency, 10GB per-partition-key-value limit (includes base table + LSI projected attributes), maximum 5 LSIs per table, must be created at table creation (cannot add/modify later). Flexibility impact (2025): GSI's ability to add indexes later makes it preferred for evolving access patterns. LSI's creation-time requirement can force complete table redesign if patterns change. When to use: GSI for most use cases (no size limit, flexible), LSI only when strong consistency required for non-primary-key queries. Cost: LSI shares table RCUs/WCUs, GSI has separate capacity billing.

99% confidence
A

Key aggregation stages: $match (filter documents, place early for performance), $group (group by key with $sum/$avg/$max/$min aggregations), $project (shape output, select/exclude/compute fields), $sort (order results, use indexes when first stage), $limit/$skip (pagination), $lookup (left outer join to another collection), $unwind (deconstruct arrays into separate documents). Stage ordering matters: Output of each stage feeds next stage sequentially. Performance optimization (2025): (1) Place $match as early as possible to reduce documents processed downstream, (2) $match can use indexes only when first stage or after $geoNear, (3) MongoDB query optimizer automatically reorders stages when safe, (4) Delay $lookup until after filtering to reduce lookups performed. Execution engine: MongoDB uses slot-based execution engine for improved performance (lower CPU/memory) when conditions met. Monitor: Use .explain('executionStats') to verify index usage and execution plan. Best practice: Filter early, project late, index $match/$sort fields.

99% confidence
A

Main levels: ONE (fastest, any 1 replica responds), QUORUM (majority, calculated as (replicas/2)+1 rounded down, balanced), LOCAL_QUORUM (majority within local datacenter, recommended for multi-DC), ALL (strongest, all replicas respond, slowest, not fault-tolerant). Default: ONE for all operations. Trade-offs: Higher consistency = higher latency and lower availability. Strong consistency formula: R+W > N (read CL + write CL > replication factor). Example: RF=3, QUORUM write (2 nodes) + QUORUM read (2 nodes) = 4 > 3, guarantees strong consistency via overlapping replicas. Production best practices (2025): Use LOCAL_QUORUM for most production single-datacenter deployments (balances consistency and availability), QUORUM for critical operations, avoid ALL (fails if any replica down) and ANY (can cause data loss). Configuration: Set per-query with session.execute(statement, ConsistencyLevel.QUORUM); Essential data (user info, prices): QUORUM/LOCAL_QUORUM. Non-critical data (reviews): ONE/LOCAL_ONE.

99% confidence
A

Scan reads entire table then applies filters (O(n) complexity), consuming RCUs for all items scanned regardless of FilterExpression. Performance impact: Scan takes 650ms vs Query's 65ms at p95, potentially hours for large tables (23GB table: 49 minutes sequential scan vs 1 minute parallel scan). Cost impact: Billed for all data scanned, not data returned - scan 100 items but filter to 1 item still consumes RCUs for 100 items. Query performs direct partition key lookup (O(1)), reading only matching items, 10x+ faster and cost-efficient. Real-world savings (2025): 42+ fewer RCUs per read when switching from Scan to Query with GSI. Design principles: Always design tables for Query access patterns using partition keys, add GSIs when new access patterns emerge, use parallel scan only for batch operations (analytics, ETL, backups) on tables ≥20GB. FilterExpression trap: Filters applied after read, no RCU savings. Alternative: DynamoDB Streams or Export to S3 for batch processing.

99% confidence
A

Arbiter is voting-only member that participates in elections with 1 vote but holds no data and cannot become primary. Use when cost constraints prevent adding third data-bearing member for election majority. PSA (Primary-Secondary-Arbiter) architecture considerations (2025): Write concern w:'majority' causes severe performance issues when secondary lags or fails - commit point lags, causing cache pressure and increased I/O. Why: Arbiters provide election majority but not data majority. w:1 writes succeed with one node down, but w:'majority' cannot. Sharded cluster impact: PSA shards lose availability if secondary unavailable (w:'majority' operations fail). Multiple arbiters prohibited since MongoDB 5.3 (can elect lagged node, causing data loss). Mitigation: Set secondary votes:0 during lag, then rs.reconfigForPSASet() when caught up. Best practice: Replace arbiter with data-bearing node when possible - allows majority writes/reads and maintains majority with one node down. Recommended: Use PSS (Primary-Secondary-Secondary) over PSA for production.

99% confidence
A

Cassandra's tunable consistency mechanism allows per-operation customization of consistency levels (CL) separately for reads and writes, enabling applications to dynamically balance availability against data accuracy. Write consistency levels (strongest to weakest): ALL (all replicas acknowledge, highest consistency), QUORUM (majority = (RF/2)+1 rounded down, balanced), LOCAL_QUORUM (quorum within local datacenter only), ONE (any single replica, fast), ANY (write-only, lowest consistency, succeeds via hinted handoff even if all replicas offline - not production recommended). Read consistency levels: ONE (fastest, may return stale), LOCAL_ONE, QUORUM, LOCAL_QUORUM, ALL (slowest, waits for all replicas), SERIAL (linearizable for lightweight transactions), LOCAL_SERIAL (linearizable within single datacenter). Strong consistency achieved via formula: R+W > N (read CL value + write CL value > replication factor). Example: RF=3, QUORUM write (2 replicas) + QUORUM read (2 replicas) = 4 > 3, guarantees overlapping replicas containing latest data. Default: ONE (eventual consistency, maximum availability). Configuration: Per-query via driver: session.execute(statement, ConsistencyLevel.QUORUM); or cqlsh CONSISTENCY command for session-level defaults. Trade-offs: Higher consistency increases write latency (waiting for more replicas) and reduces availability (fails if insufficient replicas available). Multi-datacenter: LOCAL_QUORUM recommended (avoids cross-datacenter latency while maintaining local strong consistency). Production best practice (2025): LOCAL_QUORUM for single-DC (balances consistency/availability), QUORUM for critical data, avoid ANY and ALL for regular operations. Tunable consistency is Cassandra's defining innovation enabling per-operation flexibility.

99% confidence
A

On-demand capacity mode (2025 pricing): Pay $0.25/million WRUs (write request units) and $0.25/million RRUs (read request units) with no upfront capacity planning. Automatic scaling prevents throttling, billing matches actual consumption. Cost comparison: 6.94x more expensive than fully-utilized provisioned mode but optimal for variable workloads. Decision criteria: Use on-demand when (1) Traffic highly unpredictable/spiky (>3x variation daily or flash sales), (2) Application new with unknown workload patterns, (3) Expected utilization <30% of provisioned equivalent, (4) Serverless applications requiring instant auto-scaling, (5) Development/testing with intermittent usage. Real cost example: 10M requests/month costs $2.50 on-demand vs $0.06 provisioned (100 WCUs) at full utilization. Benefits: No throttling (auto-scales instantly), billing only for actual usage, warm throughput visibility (added Nov 2024) for proactive scaling, no capacity management overhead. Provisioned capacity mode: Pre-allocate WCUs/RCUs, billed hourly ($0.00065/WCU-hour, $0.00013/RCU-hour in US East) regardless of usage. Cost advantage: 5-7x savings vs on-demand for steady workloads; reserved capacity (1-3 year commitment) adds 40-80% additional discounts. Decision criteria: Use provisioned when (1) Traffic predictable with <2x daily variance, (2) Expected sustained utilization >50%, (3) Cost optimization critical for high-traffic workloads (>50M requests/month), (4) Capacity forecasting possible from historical data. Risks: Throttling if traffic exceeds limits (requires monitoring), operational overhead for scaling adjustments, over-provisioning wastes money. Break-even analysis: Provisioned becomes cost-effective when sustained usage exceeds ~30% of allocated capacity; at 50% utilization achieve 42% cost savings vs on-demand. Hybrid approach (2025 best practice): Allocate provisioned capacity for baseline + on-demand for unpredictable peaks (enabled after Nov 2024). Switching mechanics: Toggle between modes once per 24 hours with 60-second delay between switches. Migration strategy: Start on-demand for new apps, monitor 30+ days of actual usage patterns, calculate provisioned cost vs actual on-demand spend, switch to provisioned if 42%+ cost savings evident.

99% confidence
A

Yes, $match placement is critical for performance. Best practice: Place $match as early as possible in pipeline (ideally first stage). Why: It filters documents before expensive operations, limiting total documents processed downstream. Performance impact: Early $match reduces memory usage, leverages indexes (when first stage), prevents unnecessary processing in $group/$lookup/$project stages. Example efficient pipeline: [{$match: {status: 'active'}}, {$group: {_id: '$category', total: {$sum: '$amount'}}}] vs inefficient: [{$group: {_id: '$category', total: {$sum: '$amount'}}}, {$match: {'_id': 'electronics'}}]. Index usage: $match can use indexes only when it's the first stage or immediately after $geoNear. MongoDB query optimizer automatically reorders some stages, moving $match earlier when safe. Combine with $sort early for index-covered sorts. Monitor with explain: true to verify index usage and execution plan.

99% confidence
A

Cassandra is usually classified as AP (Available and Partition-tolerant), prioritizing availability during network partitions with eventual consistency. However, this is oversimplification - tunable consistency allows Cassandra to act as CP (Consistent and Partition-tolerant) or AP per operation. How it works: Set consistency level ONE for AP behavior (highest availability, any replica responds), or QUORUM/ALL for CP behavior (strong consistency, majority/all replicas respond). Configuration flexibility (2025): Choose per-query basis: session.execute(statement, ConsistencyLevel.QUORUM); Trade-offs: ONE provides fastest reads with eventual consistency, QUORUM provides strong consistency (when R+W > N) but higher latency and lower availability (operations fail if insufficient replicas available). CAP positioning: Cassandra seeks to satisfy all three CAP requirements simultaneously by allowing applications to choose consistency-availability balance dynamically. Use cases: AP mode for high-traffic, low-latency applications tolerating eventual consistency; CP mode for financial transactions requiring strong consistency. Best practice: LOCAL_QUORUM for production balances consistency and availability.

99% confidence
A

No, LSIs (Local Secondary Indexes) must be defined at table creation time and cannot be added, modified, or deleted later. This is permanent limitation in DynamoDB architecture. Impact: If access patterns evolve requiring new LSI, you must create new table with LSI, migrate all data, update application code, then delete old table - complete table redesign. Contrast with GSI: Global Secondary Indexes can be created, modified, or deleted anytime after table creation with automatic backfilling. Table limits (2025): Maximum 5 LSIs per table (cannot be increased via AWS support), but up to 20 GSIs (increasable). Design implications: LSIs require upfront access pattern planning, making them less flexible for evolving applications. Best practice: Prefer GSIs for most use cases due to flexibility, only use LSI when strong consistency required for non-primary-key queries and access patterns are stable and well-understood at design time. Planning: Document all query patterns before table creation if using LSIs to avoid costly migrations.

99% confidence
A

DynamoDB LSI (Local Secondary Index) has 10GB per-partition-key-value size limit. Limit calculation: Total size of all items with same partition key value + all LSI projected attributes for that partition key ≤ 10GB. Example: If partition key 'userId=123' has 9GB of base table items + 2GB of LSI projections = 11GB, writes fail with ItemCollectionSizeLimitExceededException. Why it exists: LSIs are stored on same partition as base table items (co-located for performance). Impact: Applications with high-cardinality sort keys or large item sizes hit limit. No such limit for GSIs (they're distributed separately across partitions). Monitoring: Enable ItemCollectionMetrics to track partition sizes approaching limit. Workarounds: Use GSI instead (no size limit, but eventual consistency), reduce projected attributes in LSI (project only essential fields), shard data across multiple partition key values. Best practice (2025): Prefer GSIs for most use cases - LSIs only when strong consistency required for non-primary-key queries.

99% confidence
A

MongoDB automatically creates multikey index when indexing array-containing fields. Each array element gets indexed separately, creating multiple index entries per document. Example: db.products.createIndex({tags: 1}); on document {tags: ['electronics', 'wireless', 'portable']} creates 3 index entries. Query optimization: db.products.find({tags: 'electronics'}); efficiently uses multikey index. Compound multikey restriction: At most one indexed field per document can be an array. Valid: {tags: ['a', 'b'], category: 'electronics'} with index {tags: 1, category: 1}. Invalid: {tags: ['a'], sizes: ['S', 'M']} with index {tags: 1, sizes: 1} - MongoDB rejects on insert. Performance considerations: Multikey indexes are larger (multiple entries per document), slower writes (updating array updates multiple index entries). Array size impact: Index size grows with array length. Best practice (2025): Use for tag systems, skill sets, permissions arrays. Avoid indexing very large arrays (>100 elements). Monitor index size with db.collection.stats().

99% confidence
A

Cassandra distributes data via consistent hashing: partition key → Murmur3Partitioner hash (default since v1.2) → 64-bit token (range -2^63 to +2^63-1) → specific node on token ring. Hash function advantage: Murmur3 is 3-5x faster than legacy MD5, creates deterministic hash so same partition key value always produces identical token. Token ring architecture: Cluster nodes own continuous token ranges using virtual nodes (vnodes). Default: 8 vnodes per node distribute token ranges throughout cluster (enables ~10% workload variance vs single token per node). Distribution flow: Write partition_key='user_id=123' → hash('user_id=123') = token:8675309 → cluster finds node owning range [8000000-9000000] → data written to that node. Even distribution requirements (2025): (1) High cardinality (millions of unique partition key values), (2) Uniform distribution (not monotonic timestamps/auto-incrementing IDs), (3) Matches query access patterns (required in WHERE clause). Hot partition causes and impact: Low cardinality (e.g., country column for 90% USA data), monotonic partition keys (sequential timestamps write to consecutive token ranges hitting same nodes), traffic skew (single user generates 100x traffic of others). Performance degradation: Hot partitions cause node CPU throttling, increased garbage collection pauses, replication lag on overwhelmed replicas, read timeouts, operator burden. Mitigation strategies: Use composite partition key ((user_id, hour_bucket)) to increase cardinality, implement bucketing ((user_id, bucket_id)) for high-volume entities, analyze token balance with nodetool status (check 'Owns' percentage per node) and cfstats for partition sizes. Query implication: All queries must include partition key to enable O(1) token lookup - omitting partition key forces full-cluster scan. Monitoring: nodetool status shows token distribution evenness, cfstats reveals uneven partition sizes indicating hotspots.

99% confidence
A

No, FilterExpression does not reduce RCU (Read Capacity Unit) consumption. Filters are applied after items are read from table, so you're charged for all items scanned before filtering, not for filtered results returned to client. How it works: DynamoDB reads items → consumes RCUs based on data read → applies FilterExpression → returns filtered results. Cost calculation (2025): RCUs based on cumulative size of items accessed, not returned. Example: Scan 100 items of 4KB each (400KB total) with FilterExpression returning 1 item = ~100 RCUs consumed (strongly consistent) or ~50 RCUs (eventually consistent), not 1 RCU. One RCU: One strongly consistent read per second for items up to 4KB, or two eventually consistent reads. Cost optimization: Use partition/sort keys in KeyConditionExpression for targeted Query operations instead of Scan with FilterExpression. Real savings: Query with proper keys consumes RCUs only for matching items. Add GSIs for new access patterns. FilterExpression use case: Only for additional filtering after key-based Query when filter criteria cannot be part of key design.

99% confidence
A

Eventual consistency means all replicas converge to same value over time but may temporarily return different values. Deliberate trade-off for high availability during network partitions or node failures (AP in CAP theorem). How it works: Write to replica A succeeds, replica B temporarily unavailable, read from B returns stale data until replication completes. Convergence mechanisms: Read repair (reconciles during reads), hinted handoff (stores writes for unavailable nodes), anti-entropy repair (background sync via nodetool repair). Achieving strong consistency: Use consistency levels where R+W > N (read + write > replication factor). Example: RF=3, QUORUM write (2 nodes) + QUORUM read (2 nodes) = 4 > 3, guarantees overlap and strong consistency. Trade-offs: Strong consistency sacrifices availability (operations fail if insufficient replicas available) and speed (higher latency waiting for multiple replicas). Best practice (2025): Use QUORUM/QUORUM for strong consistency, ONE/ONE for eventual consistency with maximum availability. Last-write-wins conflict resolution using timestamps.

99% confidence
A

Use compound indexes for queries filtering on multiple fields together - significantly faster than multiple single-field indexes. Compound index advantages: (1) Supports prefix queries (left-to-right matching), (2) Enables covered queries (query + projection use only indexed fields, no document reads), (3) Single index lookup vs multiple lookups. Example: db.users.createIndex({age: 1, city: 1, status: 1}); supports queries on {age}, {age, city}, and {age, city, status}. Does not support queries on {city} or {status} alone (must match from left). MongoDB limitation: Cannot efficiently merge multiple single-field indexes (index intersection requires scanning both indexes, usually slower than compound). Performance comparison: Compound index requires one lookup to find matching documents; multiple single-field indexes require picking highest-cardinality index, then filtering results. Trade-offs: Compound indexes increase write overhead (one index to update) but less than multiple single indexes. Best practice (2025): Create compound indexes matching your query patterns, order fields by cardinality (highest first) or query frequency. Monitor with db.collection.stats() and explain('executionStats').

99% confidence
A

Parallel scan divides table into logical segments, scanning each segment in parallel with multiple workers (threads or processes). Performance improvement: 50-70x faster than sequential scan - 23GB table scanned in 1 minute vs 49 minutes sequential. Implementation: Specify TotalSegments (number of segments) and Segment (0-indexed segment to scan per worker). AWS recommendation: Start with 1 segment per 2GB data (e.g., 30GB table = 15 segments). Optimal: 100-200 segments in single process provides 50x+ speed improvement. Use when: (1) Table ≥ 20GB, (2) Provisioned throughput underutilized, (3) Sequential scan too slow, (4) Full table export/backup needed. Limitations: Requires uniform hash key distribution (tables with 100% same hash key see no benefit), consumes significant RCUs (can throttle other operations), increases costs. Best practice (2025): Avoid scan if possible (design for Query access patterns instead), use parallel scan only for batch operations (analytics, ETL, backups), monitor consumed capacity to prevent throttling production traffic. Alternative: Use DynamoDB Streams or Export to S3 for batch processing.

99% confidence
A

Yes, all GSIs (Global Secondary Indexes) have eventual consistency only - no strongly consistent read option available. Propagation timing (2025): Updates to base table propagate to GSI within single-digit milliseconds under normal conditions (typically <10ms). How it works: DynamoDB uses asynchronous replication - write commits to base table → operation added to internal queue → write acknowledged to client → background service processes queue to update GSIs. Potential delays: Under normal conditions, propagation is fast. During failures (leader node died, new leader election), delays can extend to seconds. Capacity impact: If GSI doesn't have sufficient provisioned throughput or exceeds partition limits, replication lag increases significantly. Query implications: GSI queries may return stale data - recently written items might not appear in GSI results immediately. Contrast: LSIs (Local Secondary Indexes) support both strong and eventual consistency options. Workarounds: If strong consistency required, use LSI instead (if same partition key works) or query base table directly. Monitor: Track GSI replication lag using CloudWatch metrics for capacity planning.

99% confidence
A

Best practice (2025): Place $project as the final stage in aggregation pipelines for field selection and output shaping. Critical reason: $project placement affects $sort index usage - $sort can use indexes only if NOT preceded by $project, $unwind, or $group stages. Example: [{$match: {status: 'active'}}, {$sort: {date: -1}}, {$project: {name: 1, date: 1}}] allows $sort to use index on date field. Placing $project before $sort prevents index usage. Counterintuitive finding: Early $project for field reduction provides minimal performance benefit because MongoDB's dependency analysis automatically identifies required fields and only retrieves them - no manual projection needed for this optimization. Memory impact: While $project reduces memory per document (smaller documents use less RAM), this rarely exceeds the 100MB pipeline memory limit unless dealing with enormous result sets. Only exception to late-placement rule: Use early $project to compute fields (derived fields) that subsequent stages depend on. Example: [{$project: {total: {$add: ['$price', '$tax']}}}, {$match: {total: {$gt: 100}}}] computes 'total' field for $match filtering. Modern alternative (MongoDB 4.2+): Use $set/$unset instead of $project for computing/excluding fields - clearer intent, less verbose, avoids accidental field inclusion/exclusion. Monitor with explain('executionStats') to verify index usage and confirm $sort execution plan. Automatic optimizer: MongoDB automatically reorders safe operations (e.g., moving $match conditions before $project) to optimize performance.

99% confidence
A

MongoDB 5.3+ disables multiple arbiter support by default, recommending maximum one arbiter per replica set. Multiple arbiters remain technically possible only by explicitly enabling with allowMultipleArbiters: true parameter on each node. Critical data loss risk from multiple arbiters: If a secondary falls behind the primary, multiple arbiter votes can elect the lagged node as new primary. Scenario: 5-member set (3 data-bearing nodes + 2 arbiters). If 2 data-bearing nodes fail, remaining lagged node + 2 arbiters = 3/5 votes (majority). Newly elected primary won't have unreplicated writes even if those writes were majority-committed under old configuration. Additional risks: (1) Multiple arbiters prevent reliable use of majority write concern for consistency guarantees, (2) Reduces probability of having data-bearing node majority after failures, (3) Undermines replica set availability and durability properties. Release constraints (2025): Arbiters are NOT supported with quarterly rapid releases - only compatible with LTS (Long Term Support) releases if deploying any arbiters. Best practices: Use maximum one arbiter per replica set, prefer PSS (Primary-Secondary-Secondary) over PSA (Primary-Secondary-Arbiter) architecture for production, deploy arbiters only when cost/licensing prevents adding third data-bearing member. Configuration: Set arbiterOnly: true in replica set configuration. Arbiters participate in primary elections with single vote but have no data storage capability. Upgrade guidance: When upgrading from pre-5.3 clusters with multiple arbiters, either (1) reconfigure to single arbiter, (2) explicitly set allowMultipleArbiters: true on all nodes, or (3) allow default behavior to disable additional arbiters.

99% confidence
A

QUORUM formula: (replication_factor / 2) + 1, rounded down to whole number. Requires majority of replicas to acknowledge operation. Examples: RF=3 → QUORUM=2 (tolerates 1 node down), RF=6 → QUORUM=4 (tolerates 2 nodes down). Multi-datacenter: QUORUM uses sum of all replication factors across all datacenters. Example: 2 datacenters each with RF=3 → total RF=6 → QUORUM=4 (tolerates 2 nodes down cluster-wide). LOCAL_QUORUM formula: (local_datacenter_replication_factor / 2) + 1. Scopes to single datacenter, avoiding cross-datacenter latency. Example: RF=3 in local DC → LOCAL_QUORUM=2. Strong consistency achievement: R+W > N (read nodes + write nodes > replication factor). Example: RF=3, QUORUM write (2) + QUORUM read (2) = 4 > 3, guarantees overlapping replicas for strong consistency. Production use (2025): LOCAL_QUORUM recommended for multi-datacenter clusters (lower latency), QUORUM for single-datacenter or global consistency needs. Benefits: Balances consistency, availability, and performance - most common production configuration.

99% confidence
A

AWS introduced two major DynamoDB enhancements in November 2024: (1) On-demand throughput price reduction: Significantly lowered on-demand mode costs, making it cost-competitive with provisioned capacity for variable workloads. Following this reduction, on-demand became preferred choice for most serverless applications with unpredictable traffic patterns. Current pricing: $1.25/million WRUs, $0.25/million RRUs. (2) Warm throughput capabilities: Added real-time visibility into burst capacity and throughput metrics. Enables proactive scaling before traffic surges, preventing throttling. Benefit: Applications can monitor available burst capacity and scale provisioned capacity preemptively rather than reacting to throttling errors. Impact on capacity planning: On-demand now viable for wider range of workloads, warm throughput monitoring enables more precise provisioned capacity planning. Cost comparison shift: On-demand break-even point improved from ~40% utilization to ~30% utilization. Best practice (2025): Start new applications with on-demand mode, leverage warm throughput metrics for capacity planning, consider migration from provisioned to on-demand if utilization <30%.

99% confidence
A

$lookup performs left outer join to another collection in same database, similar to SQL JOIN. Syntax: {$lookup: {from: 'collection', localField: 'field', foreignField: 'field', as: 'arrayField'}}. Adds matched documents from joined collection as array field in output. Performance considerations (2025): $lookup performs separate collection lookup per document, can be slow on large datasets. Optimization techniques: (1) Index foreign fields for faster lookups (critical), (2) Use $match before $lookup to filter documents and reduce lookups performed, (3) Place $lookup after $limit to limit number of join operations, (4) Use $project to include only necessary fields minimizing memory usage, (5) Consider data denormalization for frequently accessed joins - duplicate rarely-changing data to avoid $lookups. Query optimizer: MongoDB coalesces $unwind and $match into $lookup stage when possible, uses slot-based execution engine for improved performance. Best practice: Structure collections so common queries avoid $lookups when possible. Monitor: Use .explain('executionStats') to identify $lookup bottlenecks and verify index usage on foreign collection.

99% confidence
A

Compound indexes index multiple fields to optimize queries filtering on multiple criteria. Created with db.collection.createIndex({field1: 1, field2: 1}); - supports queries on field1 or {field1, field2} (left-to-right prefix matching). Multikey indexes handle array-containing fields, automatically created when indexing arrays. MongoDB creates separate index entries for each array element. Example: {tags: ['a', 'b']} creates 2 index entries. Compound multikey restriction: At most one indexed field per document can be an array. Valid: {tags: ['a', 'b'], category: 'x'} with index {tags: 1, category: 1}. Invalid: {tags: ['a'], sizes: ['S', 'M']} with same compound index (rejected on insert). ESR guideline (2025): Order compound index fields as Equality, Sort, Range for optimal performance. Best practice: Prefer single compound indexes over multiple single-field indexes - faster than index intersection. Monitor with db.collection.explain('executionStats') to verify index usage.

99% confidence
A

Primary key = Partition Key + Clustering Columns (optional). Syntax: PRIMARY KEY ((partition_key), clustering_col1, clustering_col2). Partition key determines which node stores data via consistent hashing - partition key value → hash → token → specific node. Distributes data evenly across cluster nodes. Clustering key sorts data within partition, ordering rows with same partition key value. Example: PRIMARY KEY ((user_id), timestamp, event_type) - user_id distributes across nodes, data sorted by timestamp then event_type within each partition. Composite partition keys: ((col1, col2)) increases cardinality for better distribution. Query requirements (2025): Partition key required in WHERE clause (targeted reads), clustering columns optional for range queries within partition. Queries without partition key trigger expensive full-cluster scans. Good partition key characteristics: High cardinality (many unique values), evenly distributed values, matches query access patterns. Monitor distribution: nodetool status checks data balance across nodes.

99% confidence
A

GSI (Global Secondary Index): Different partition/sort keys from base table, queries span all partitions globally, separate provisioned throughput, eventual consistency only (single-digit millisecond propagation lag typical), no size limit, can be created/deleted anytime. LSI (Local Secondary Index): Same partition key as base table with different sort key, scoped to single partition, shares table throughput, supports strong or eventual consistency, 10GB per-partition-key-value limit (includes base table + LSI projected attributes), maximum 5 LSIs per table, must be created at table creation (cannot add/modify later). Flexibility impact (2025): GSI's ability to add indexes later makes it preferred for evolving access patterns. LSI's creation-time requirement can force complete table redesign if patterns change. When to use: GSI for most use cases (no size limit, flexible), LSI only when strong consistency required for non-primary-key queries. Cost: LSI shares table RCUs/WCUs, GSI has separate capacity billing.

99% confidence
A

Key aggregation stages: $match (filter documents, place early for performance), $group (group by key with $sum/$avg/$max/$min aggregations), $project (shape output, select/exclude/compute fields), $sort (order results, use indexes when first stage), $limit/$skip (pagination), $lookup (left outer join to another collection), $unwind (deconstruct arrays into separate documents). Stage ordering matters: Output of each stage feeds next stage sequentially. Performance optimization (2025): (1) Place $match as early as possible to reduce documents processed downstream, (2) $match can use indexes only when first stage or after $geoNear, (3) MongoDB query optimizer automatically reorders stages when safe, (4) Delay $lookup until after filtering to reduce lookups performed. Execution engine: MongoDB uses slot-based execution engine for improved performance (lower CPU/memory) when conditions met. Monitor: Use .explain('executionStats') to verify index usage and execution plan. Best practice: Filter early, project late, index $match/$sort fields.

99% confidence
A

Main levels: ONE (fastest, any 1 replica responds), QUORUM (majority, calculated as (replicas/2)+1 rounded down, balanced), LOCAL_QUORUM (majority within local datacenter, recommended for multi-DC), ALL (strongest, all replicas respond, slowest, not fault-tolerant). Default: ONE for all operations. Trade-offs: Higher consistency = higher latency and lower availability. Strong consistency formula: R+W > N (read CL + write CL > replication factor). Example: RF=3, QUORUM write (2 nodes) + QUORUM read (2 nodes) = 4 > 3, guarantees strong consistency via overlapping replicas. Production best practices (2025): Use LOCAL_QUORUM for most production single-datacenter deployments (balances consistency and availability), QUORUM for critical operations, avoid ALL (fails if any replica down) and ANY (can cause data loss). Configuration: Set per-query with session.execute(statement, ConsistencyLevel.QUORUM); Essential data (user info, prices): QUORUM/LOCAL_QUORUM. Non-critical data (reviews): ONE/LOCAL_ONE.

99% confidence
A

Scan reads entire table then applies filters (O(n) complexity), consuming RCUs for all items scanned regardless of FilterExpression. Performance impact: Scan takes 650ms vs Query's 65ms at p95, potentially hours for large tables (23GB table: 49 minutes sequential scan vs 1 minute parallel scan). Cost impact: Billed for all data scanned, not data returned - scan 100 items but filter to 1 item still consumes RCUs for 100 items. Query performs direct partition key lookup (O(1)), reading only matching items, 10x+ faster and cost-efficient. Real-world savings (2025): 42+ fewer RCUs per read when switching from Scan to Query with GSI. Design principles: Always design tables for Query access patterns using partition keys, add GSIs when new access patterns emerge, use parallel scan only for batch operations (analytics, ETL, backups) on tables ≥20GB. FilterExpression trap: Filters applied after read, no RCU savings. Alternative: DynamoDB Streams or Export to S3 for batch processing.

99% confidence
A

Arbiter is voting-only member that participates in elections with 1 vote but holds no data and cannot become primary. Use when cost constraints prevent adding third data-bearing member for election majority. PSA (Primary-Secondary-Arbiter) architecture considerations (2025): Write concern w:'majority' causes severe performance issues when secondary lags or fails - commit point lags, causing cache pressure and increased I/O. Why: Arbiters provide election majority but not data majority. w:1 writes succeed with one node down, but w:'majority' cannot. Sharded cluster impact: PSA shards lose availability if secondary unavailable (w:'majority' operations fail). Multiple arbiters prohibited since MongoDB 5.3 (can elect lagged node, causing data loss). Mitigation: Set secondary votes:0 during lag, then rs.reconfigForPSASet() when caught up. Best practice: Replace arbiter with data-bearing node when possible - allows majority writes/reads and maintains majority with one node down. Recommended: Use PSS (Primary-Secondary-Secondary) over PSA for production.

99% confidence
A

Cassandra's tunable consistency mechanism allows per-operation customization of consistency levels (CL) separately for reads and writes, enabling applications to dynamically balance availability against data accuracy. Write consistency levels (strongest to weakest): ALL (all replicas acknowledge, highest consistency), QUORUM (majority = (RF/2)+1 rounded down, balanced), LOCAL_QUORUM (quorum within local datacenter only), ONE (any single replica, fast), ANY (write-only, lowest consistency, succeeds via hinted handoff even if all replicas offline - not production recommended). Read consistency levels: ONE (fastest, may return stale), LOCAL_ONE, QUORUM, LOCAL_QUORUM, ALL (slowest, waits for all replicas), SERIAL (linearizable for lightweight transactions), LOCAL_SERIAL (linearizable within single datacenter). Strong consistency achieved via formula: R+W > N (read CL value + write CL value > replication factor). Example: RF=3, QUORUM write (2 replicas) + QUORUM read (2 replicas) = 4 > 3, guarantees overlapping replicas containing latest data. Default: ONE (eventual consistency, maximum availability). Configuration: Per-query via driver: session.execute(statement, ConsistencyLevel.QUORUM); or cqlsh CONSISTENCY command for session-level defaults. Trade-offs: Higher consistency increases write latency (waiting for more replicas) and reduces availability (fails if insufficient replicas available). Multi-datacenter: LOCAL_QUORUM recommended (avoids cross-datacenter latency while maintaining local strong consistency). Production best practice (2025): LOCAL_QUORUM for single-DC (balances consistency/availability), QUORUM for critical data, avoid ANY and ALL for regular operations. Tunable consistency is Cassandra's defining innovation enabling per-operation flexibility.

99% confidence
A

On-demand capacity mode (2025 pricing): Pay $0.25/million WRUs (write request units) and $0.25/million RRUs (read request units) with no upfront capacity planning. Automatic scaling prevents throttling, billing matches actual consumption. Cost comparison: 6.94x more expensive than fully-utilized provisioned mode but optimal for variable workloads. Decision criteria: Use on-demand when (1) Traffic highly unpredictable/spiky (>3x variation daily or flash sales), (2) Application new with unknown workload patterns, (3) Expected utilization <30% of provisioned equivalent, (4) Serverless applications requiring instant auto-scaling, (5) Development/testing with intermittent usage. Real cost example: 10M requests/month costs $2.50 on-demand vs $0.06 provisioned (100 WCUs) at full utilization. Benefits: No throttling (auto-scales instantly), billing only for actual usage, warm throughput visibility (added Nov 2024) for proactive scaling, no capacity management overhead. Provisioned capacity mode: Pre-allocate WCUs/RCUs, billed hourly ($0.00065/WCU-hour, $0.00013/RCU-hour in US East) regardless of usage. Cost advantage: 5-7x savings vs on-demand for steady workloads; reserved capacity (1-3 year commitment) adds 40-80% additional discounts. Decision criteria: Use provisioned when (1) Traffic predictable with <2x daily variance, (2) Expected sustained utilization >50%, (3) Cost optimization critical for high-traffic workloads (>50M requests/month), (4) Capacity forecasting possible from historical data. Risks: Throttling if traffic exceeds limits (requires monitoring), operational overhead for scaling adjustments, over-provisioning wastes money. Break-even analysis: Provisioned becomes cost-effective when sustained usage exceeds ~30% of allocated capacity; at 50% utilization achieve 42% cost savings vs on-demand. Hybrid approach (2025 best practice): Allocate provisioned capacity for baseline + on-demand for unpredictable peaks (enabled after Nov 2024). Switching mechanics: Toggle between modes once per 24 hours with 60-second delay between switches. Migration strategy: Start on-demand for new apps, monitor 30+ days of actual usage patterns, calculate provisioned cost vs actual on-demand spend, switch to provisioned if 42%+ cost savings evident.

99% confidence
A

Yes, $match placement is critical for performance. Best practice: Place $match as early as possible in pipeline (ideally first stage). Why: It filters documents before expensive operations, limiting total documents processed downstream. Performance impact: Early $match reduces memory usage, leverages indexes (when first stage), prevents unnecessary processing in $group/$lookup/$project stages. Example efficient pipeline: [{$match: {status: 'active'}}, {$group: {_id: '$category', total: {$sum: '$amount'}}}] vs inefficient: [{$group: {_id: '$category', total: {$sum: '$amount'}}}, {$match: {'_id': 'electronics'}}]. Index usage: $match can use indexes only when it's the first stage or immediately after $geoNear. MongoDB query optimizer automatically reorders some stages, moving $match earlier when safe. Combine with $sort early for index-covered sorts. Monitor with explain: true to verify index usage and execution plan.

99% confidence
A

Cassandra is usually classified as AP (Available and Partition-tolerant), prioritizing availability during network partitions with eventual consistency. However, this is oversimplification - tunable consistency allows Cassandra to act as CP (Consistent and Partition-tolerant) or AP per operation. How it works: Set consistency level ONE for AP behavior (highest availability, any replica responds), or QUORUM/ALL for CP behavior (strong consistency, majority/all replicas respond). Configuration flexibility (2025): Choose per-query basis: session.execute(statement, ConsistencyLevel.QUORUM); Trade-offs: ONE provides fastest reads with eventual consistency, QUORUM provides strong consistency (when R+W > N) but higher latency and lower availability (operations fail if insufficient replicas available). CAP positioning: Cassandra seeks to satisfy all three CAP requirements simultaneously by allowing applications to choose consistency-availability balance dynamically. Use cases: AP mode for high-traffic, low-latency applications tolerating eventual consistency; CP mode for financial transactions requiring strong consistency. Best practice: LOCAL_QUORUM for production balances consistency and availability.

99% confidence
A

No, LSIs (Local Secondary Indexes) must be defined at table creation time and cannot be added, modified, or deleted later. This is permanent limitation in DynamoDB architecture. Impact: If access patterns evolve requiring new LSI, you must create new table with LSI, migrate all data, update application code, then delete old table - complete table redesign. Contrast with GSI: Global Secondary Indexes can be created, modified, or deleted anytime after table creation with automatic backfilling. Table limits (2025): Maximum 5 LSIs per table (cannot be increased via AWS support), but up to 20 GSIs (increasable). Design implications: LSIs require upfront access pattern planning, making them less flexible for evolving applications. Best practice: Prefer GSIs for most use cases due to flexibility, only use LSI when strong consistency required for non-primary-key queries and access patterns are stable and well-understood at design time. Planning: Document all query patterns before table creation if using LSIs to avoid costly migrations.

99% confidence
A

DynamoDB LSI (Local Secondary Index) has 10GB per-partition-key-value size limit. Limit calculation: Total size of all items with same partition key value + all LSI projected attributes for that partition key ≤ 10GB. Example: If partition key 'userId=123' has 9GB of base table items + 2GB of LSI projections = 11GB, writes fail with ItemCollectionSizeLimitExceededException. Why it exists: LSIs are stored on same partition as base table items (co-located for performance). Impact: Applications with high-cardinality sort keys or large item sizes hit limit. No such limit for GSIs (they're distributed separately across partitions). Monitoring: Enable ItemCollectionMetrics to track partition sizes approaching limit. Workarounds: Use GSI instead (no size limit, but eventual consistency), reduce projected attributes in LSI (project only essential fields), shard data across multiple partition key values. Best practice (2025): Prefer GSIs for most use cases - LSIs only when strong consistency required for non-primary-key queries.

99% confidence
A

MongoDB automatically creates multikey index when indexing array-containing fields. Each array element gets indexed separately, creating multiple index entries per document. Example: db.products.createIndex({tags: 1}); on document {tags: ['electronics', 'wireless', 'portable']} creates 3 index entries. Query optimization: db.products.find({tags: 'electronics'}); efficiently uses multikey index. Compound multikey restriction: At most one indexed field per document can be an array. Valid: {tags: ['a', 'b'], category: 'electronics'} with index {tags: 1, category: 1}. Invalid: {tags: ['a'], sizes: ['S', 'M']} with index {tags: 1, sizes: 1} - MongoDB rejects on insert. Performance considerations: Multikey indexes are larger (multiple entries per document), slower writes (updating array updates multiple index entries). Array size impact: Index size grows with array length. Best practice (2025): Use for tag systems, skill sets, permissions arrays. Avoid indexing very large arrays (>100 elements). Monitor index size with db.collection.stats().

99% confidence
A

Cassandra distributes data via consistent hashing: partition key → Murmur3Partitioner hash (default since v1.2) → 64-bit token (range -2^63 to +2^63-1) → specific node on token ring. Hash function advantage: Murmur3 is 3-5x faster than legacy MD5, creates deterministic hash so same partition key value always produces identical token. Token ring architecture: Cluster nodes own continuous token ranges using virtual nodes (vnodes). Default: 8 vnodes per node distribute token ranges throughout cluster (enables ~10% workload variance vs single token per node). Distribution flow: Write partition_key='user_id=123' → hash('user_id=123') = token:8675309 → cluster finds node owning range [8000000-9000000] → data written to that node. Even distribution requirements (2025): (1) High cardinality (millions of unique partition key values), (2) Uniform distribution (not monotonic timestamps/auto-incrementing IDs), (3) Matches query access patterns (required in WHERE clause). Hot partition causes and impact: Low cardinality (e.g., country column for 90% USA data), monotonic partition keys (sequential timestamps write to consecutive token ranges hitting same nodes), traffic skew (single user generates 100x traffic of others). Performance degradation: Hot partitions cause node CPU throttling, increased garbage collection pauses, replication lag on overwhelmed replicas, read timeouts, operator burden. Mitigation strategies: Use composite partition key ((user_id, hour_bucket)) to increase cardinality, implement bucketing ((user_id, bucket_id)) for high-volume entities, analyze token balance with nodetool status (check 'Owns' percentage per node) and cfstats for partition sizes. Query implication: All queries must include partition key to enable O(1) token lookup - omitting partition key forces full-cluster scan. Monitoring: nodetool status shows token distribution evenness, cfstats reveals uneven partition sizes indicating hotspots.

99% confidence
A

No, FilterExpression does not reduce RCU (Read Capacity Unit) consumption. Filters are applied after items are read from table, so you're charged for all items scanned before filtering, not for filtered results returned to client. How it works: DynamoDB reads items → consumes RCUs based on data read → applies FilterExpression → returns filtered results. Cost calculation (2025): RCUs based on cumulative size of items accessed, not returned. Example: Scan 100 items of 4KB each (400KB total) with FilterExpression returning 1 item = ~100 RCUs consumed (strongly consistent) or ~50 RCUs (eventually consistent), not 1 RCU. One RCU: One strongly consistent read per second for items up to 4KB, or two eventually consistent reads. Cost optimization: Use partition/sort keys in KeyConditionExpression for targeted Query operations instead of Scan with FilterExpression. Real savings: Query with proper keys consumes RCUs only for matching items. Add GSIs for new access patterns. FilterExpression use case: Only for additional filtering after key-based Query when filter criteria cannot be part of key design.

99% confidence
A

Eventual consistency means all replicas converge to same value over time but may temporarily return different values. Deliberate trade-off for high availability during network partitions or node failures (AP in CAP theorem). How it works: Write to replica A succeeds, replica B temporarily unavailable, read from B returns stale data until replication completes. Convergence mechanisms: Read repair (reconciles during reads), hinted handoff (stores writes for unavailable nodes), anti-entropy repair (background sync via nodetool repair). Achieving strong consistency: Use consistency levels where R+W > N (read + write > replication factor). Example: RF=3, QUORUM write (2 nodes) + QUORUM read (2 nodes) = 4 > 3, guarantees overlap and strong consistency. Trade-offs: Strong consistency sacrifices availability (operations fail if insufficient replicas available) and speed (higher latency waiting for multiple replicas). Best practice (2025): Use QUORUM/QUORUM for strong consistency, ONE/ONE for eventual consistency with maximum availability. Last-write-wins conflict resolution using timestamps.

99% confidence
A

Use compound indexes for queries filtering on multiple fields together - significantly faster than multiple single-field indexes. Compound index advantages: (1) Supports prefix queries (left-to-right matching), (2) Enables covered queries (query + projection use only indexed fields, no document reads), (3) Single index lookup vs multiple lookups. Example: db.users.createIndex({age: 1, city: 1, status: 1}); supports queries on {age}, {age, city}, and {age, city, status}. Does not support queries on {city} or {status} alone (must match from left). MongoDB limitation: Cannot efficiently merge multiple single-field indexes (index intersection requires scanning both indexes, usually slower than compound). Performance comparison: Compound index requires one lookup to find matching documents; multiple single-field indexes require picking highest-cardinality index, then filtering results. Trade-offs: Compound indexes increase write overhead (one index to update) but less than multiple single indexes. Best practice (2025): Create compound indexes matching your query patterns, order fields by cardinality (highest first) or query frequency. Monitor with db.collection.stats() and explain('executionStats').

99% confidence
A

Parallel scan divides table into logical segments, scanning each segment in parallel with multiple workers (threads or processes). Performance improvement: 50-70x faster than sequential scan - 23GB table scanned in 1 minute vs 49 minutes sequential. Implementation: Specify TotalSegments (number of segments) and Segment (0-indexed segment to scan per worker). AWS recommendation: Start with 1 segment per 2GB data (e.g., 30GB table = 15 segments). Optimal: 100-200 segments in single process provides 50x+ speed improvement. Use when: (1) Table ≥ 20GB, (2) Provisioned throughput underutilized, (3) Sequential scan too slow, (4) Full table export/backup needed. Limitations: Requires uniform hash key distribution (tables with 100% same hash key see no benefit), consumes significant RCUs (can throttle other operations), increases costs. Best practice (2025): Avoid scan if possible (design for Query access patterns instead), use parallel scan only for batch operations (analytics, ETL, backups), monitor consumed capacity to prevent throttling production traffic. Alternative: Use DynamoDB Streams or Export to S3 for batch processing.

99% confidence
A

Yes, all GSIs (Global Secondary Indexes) have eventual consistency only - no strongly consistent read option available. Propagation timing (2025): Updates to base table propagate to GSI within single-digit milliseconds under normal conditions (typically <10ms). How it works: DynamoDB uses asynchronous replication - write commits to base table → operation added to internal queue → write acknowledged to client → background service processes queue to update GSIs. Potential delays: Under normal conditions, propagation is fast. During failures (leader node died, new leader election), delays can extend to seconds. Capacity impact: If GSI doesn't have sufficient provisioned throughput or exceeds partition limits, replication lag increases significantly. Query implications: GSI queries may return stale data - recently written items might not appear in GSI results immediately. Contrast: LSIs (Local Secondary Indexes) support both strong and eventual consistency options. Workarounds: If strong consistency required, use LSI instead (if same partition key works) or query base table directly. Monitor: Track GSI replication lag using CloudWatch metrics for capacity planning.

99% confidence
A

Best practice (2025): Place $project as the final stage in aggregation pipelines for field selection and output shaping. Critical reason: $project placement affects $sort index usage - $sort can use indexes only if NOT preceded by $project, $unwind, or $group stages. Example: [{$match: {status: 'active'}}, {$sort: {date: -1}}, {$project: {name: 1, date: 1}}] allows $sort to use index on date field. Placing $project before $sort prevents index usage. Counterintuitive finding: Early $project for field reduction provides minimal performance benefit because MongoDB's dependency analysis automatically identifies required fields and only retrieves them - no manual projection needed for this optimization. Memory impact: While $project reduces memory per document (smaller documents use less RAM), this rarely exceeds the 100MB pipeline memory limit unless dealing with enormous result sets. Only exception to late-placement rule: Use early $project to compute fields (derived fields) that subsequent stages depend on. Example: [{$project: {total: {$add: ['$price', '$tax']}}}, {$match: {total: {$gt: 100}}}] computes 'total' field for $match filtering. Modern alternative (MongoDB 4.2+): Use $set/$unset instead of $project for computing/excluding fields - clearer intent, less verbose, avoids accidental field inclusion/exclusion. Monitor with explain('executionStats') to verify index usage and confirm $sort execution plan. Automatic optimizer: MongoDB automatically reorders safe operations (e.g., moving $match conditions before $project) to optimize performance.

99% confidence
A

MongoDB 5.3+ disables multiple arbiter support by default, recommending maximum one arbiter per replica set. Multiple arbiters remain technically possible only by explicitly enabling with allowMultipleArbiters: true parameter on each node. Critical data loss risk from multiple arbiters: If a secondary falls behind the primary, multiple arbiter votes can elect the lagged node as new primary. Scenario: 5-member set (3 data-bearing nodes + 2 arbiters). If 2 data-bearing nodes fail, remaining lagged node + 2 arbiters = 3/5 votes (majority). Newly elected primary won't have unreplicated writes even if those writes were majority-committed under old configuration. Additional risks: (1) Multiple arbiters prevent reliable use of majority write concern for consistency guarantees, (2) Reduces probability of having data-bearing node majority after failures, (3) Undermines replica set availability and durability properties. Release constraints (2025): Arbiters are NOT supported with quarterly rapid releases - only compatible with LTS (Long Term Support) releases if deploying any arbiters. Best practices: Use maximum one arbiter per replica set, prefer PSS (Primary-Secondary-Secondary) over PSA (Primary-Secondary-Arbiter) architecture for production, deploy arbiters only when cost/licensing prevents adding third data-bearing member. Configuration: Set arbiterOnly: true in replica set configuration. Arbiters participate in primary elections with single vote but have no data storage capability. Upgrade guidance: When upgrading from pre-5.3 clusters with multiple arbiters, either (1) reconfigure to single arbiter, (2) explicitly set allowMultipleArbiters: true on all nodes, or (3) allow default behavior to disable additional arbiters.

99% confidence
A

QUORUM formula: (replication_factor / 2) + 1, rounded down to whole number. Requires majority of replicas to acknowledge operation. Examples: RF=3 → QUORUM=2 (tolerates 1 node down), RF=6 → QUORUM=4 (tolerates 2 nodes down). Multi-datacenter: QUORUM uses sum of all replication factors across all datacenters. Example: 2 datacenters each with RF=3 → total RF=6 → QUORUM=4 (tolerates 2 nodes down cluster-wide). LOCAL_QUORUM formula: (local_datacenter_replication_factor / 2) + 1. Scopes to single datacenter, avoiding cross-datacenter latency. Example: RF=3 in local DC → LOCAL_QUORUM=2. Strong consistency achievement: R+W > N (read nodes + write nodes > replication factor). Example: RF=3, QUORUM write (2) + QUORUM read (2) = 4 > 3, guarantees overlapping replicas for strong consistency. Production use (2025): LOCAL_QUORUM recommended for multi-datacenter clusters (lower latency), QUORUM for single-datacenter or global consistency needs. Benefits: Balances consistency, availability, and performance - most common production configuration.

99% confidence
A

AWS introduced two major DynamoDB enhancements in November 2024: (1) On-demand throughput price reduction: Significantly lowered on-demand mode costs, making it cost-competitive with provisioned capacity for variable workloads. Following this reduction, on-demand became preferred choice for most serverless applications with unpredictable traffic patterns. Current pricing: $1.25/million WRUs, $0.25/million RRUs. (2) Warm throughput capabilities: Added real-time visibility into burst capacity and throughput metrics. Enables proactive scaling before traffic surges, preventing throttling. Benefit: Applications can monitor available burst capacity and scale provisioned capacity preemptively rather than reacting to throttling errors. Impact on capacity planning: On-demand now viable for wider range of workloads, warm throughput monitoring enables more precise provisioned capacity planning. Cost comparison shift: On-demand break-even point improved from ~40% utilization to ~30% utilization. Best practice (2025): Start new applications with on-demand mode, leverage warm throughput metrics for capacity planning, consider migration from provisioned to on-demand if utilization <30%.

99% confidence