Intermediate 25 Questions • ~6 hrs study

NoSQL & Firebase

NoSQL databases — MongoDB, Redis, Firebase Realtime Database, document modeling, CAP theorem, and when to choose NoSQL over relational databases.

1

When would you choose NoSQL over SQL?

Short Answer

Choose NoSQL when: schema is flexible/evolving, need horizontal scaling, handling unstructured data (JSON, logs), high write throughput needed, or data is naturally hierarchical/graph-based.

Use Case SQL NoSQL
Financial transactions✅ ACID needed
Social media posts✅ Flexible schema
Real-time analytics✅ High throughput
E-commerce catalogPossible✅ Varied attributes

💡 Memory Trick: "SQL = strict relationships + ACID | NoSQL = flexibility + scale + speed"

2

Explain the CAP theorem.

Short Answer

CAP theorem: A distributed system can only guarantee 2 of 3 — Consistency (all nodes see same data), Availability (every request gets a response), Partition Tolerance (system works despite network failures). In practice, P is mandatory, so you choose between CP and AP.

Examples

  • CP (Consistency + Partition): MongoDB, Redis Cluster, HBase
  • AP (Availability + Partition): Cassandra, DynamoDB, CouchDB
  • CA (no partition tolerance): Traditional RDBMS (single node)

💡 Memory Trick: "CAP = Pick 2 of 3. Network partitions WILL happen, so really it's C vs A"

3

What are the types of NoSQL databases?

Short Answer

Four main types: Document (MongoDB, Firestore), Key-Value (Redis, DynamoDB), Column-Family (Cassandra, HBase), Graph (Neo4j, Amazon Neptune). Each optimized for different access patterns.

Type Best For Example
DocumentFlexible schemas, JSON dataMongoDB
Key-ValueCaching, sessionsRedis
Column-FamilyTime-series, analyticsCassandra
GraphRelationships, networksNeo4j

💡 Memory Trick: "DKCG — Document, Key-Value, Column, Graph. Match your access pattern!"

Questions 4-25 continue with the same detailed format.

Topics covered: MongoDB aggregation pipeline, Redis data structures, Firebase security rules, document modeling patterns (embedding vs referencing), sharding strategies, replication, and Firebase Realtime Database vs Firestore.

View Full Documentation →