Search This Blog

Friday, September 26, 2025

Q6-Q10

Q6: What is the difference between MongoDB and a relational database?
Q7: What are the limitations of MongoDB? How do you handle them?
Q8: What is the difference between Sharding and Partitioning in MongoDB?
Q9: What is the difference between vertical Partitioning and Normalization?

==============================================================================
Q6: What is the difference between MongoDB and a relational database?

Answer:

MongoDB: schema-less, document-based, horizontal scale-out, flexible data model.
Relational DB: strict schema, table-based, vertical scaling, strong consistency.
Architecturally, MongoDB makes sense where:
Data structures evolve frequently.
Reads and writes are distributed at scale.
Complex joins aren’t dominant.
However, for transactional consistency-heavy use cases (banking, financial core systems), I’d still consider RDBMS or a hybrid approach (polyglot persistence).

==============================================================================
Q7: What are the limitations of MongoDB? How do you handle them?

Answer:

Limitations:
  • Less suited for heavy relational joins.
  • Document size limit (16 MB).
  • Write amplification with large indexes.
  • Transactions come with performance overhead.

As an architect, I’d mitigate by:
  • Choosing polyglot persistence (e.g., use MongoDB for product catalog, PostgreSQL for payments).
  • Offloading complex aggregations to data warehouses.
  • Designing sharding and replication for scale and resilience.
==============================================================================
Q8: What is the difference between Sharding and Partitioning in MongoDB?

Answer:

Aspect Partitioning Sharding
Definition Logical division of data within a single node or database, often to separate workloads or improve query performance. Horizontal scaling across multiple servers (nodes), where each shard holds a subset of the data.
Scope Usually internal to a single instance/database. Distributed across multiple nodes in a cluster.
Purpose Improve manageability, optimize queries, or segregate data. Scale writes and reads horizontally, handle very large datasets, ensure high availability.
Implementation in MongoDB MongoDB doesn’t have explicit “partitioning” in the classic RDBMS sense. You can simulate partitioning using collections or databases per category. Implemented via sharding, which uses a shard key to distribute data across shards. Includes config servers and mongos routers to manage routing.
Fault tolerance Limited — if node fails, data is lost unless replicated. High — usually combined with replica sets per shard for redundancy.
Complexity Low — simple logical separation. High — requires careful shard key selection, balancing, and operational management.




==============================================================================
Q9: What is the difference between vertical Partitioning, Horizontal Partioning and Normalization?

Answer:

They look similar at first glance, but they’re not the same thing. Let’s untangle them.

Vertical Partitioning

  • Splitting a table into multiple tables based on columns.
  • Done mostly for performance, manageability, or storage optimization.
  • Example: 




Normalization

  • A database design process to reduce data redundancy and improve data integrity.
  • It breaks down a table into multiple tables based on functional dependencies.
  • Example: A Customer table storing city names directly leads to repeating the same city thousands of times.
  • Normalization moves city info into a City table and links via foreign key.

The Key Difference

  • Vertical Partitioning is a physical optimization technique (to improve performance and manageability).
  • Normalization is a logical design principle (to ensure consistency and reduce redundancy).
  • Sometimes, vertical partitioning looks like normalization because both result in more tables. But their motivation is different:
  • If you’re doing it to enforce data integrity, that’s normalization.
  • If you’re doing it to speed up queries or reduce I/O, that’s vertical partitioning.

==============================================================================


==============================================================================

Notes

  • MongoDB is a document database. It stores data in a type of JSON format called BSON
  • A record in MongoDB is Document. eg 
{
title: "Post Title 1",
body: "Body of post.",
category: "News",
likes: 1,
tags: ["news", "events"],
date: Date()
}

  •  Query db.posts.find( {category: "News"} ) will find all the documents (Records) in database with key-Category and Value - "News"
  •  In MongoDB, instead of tables these are called collections.
  • The MongoDB Query API is the way you will interact with your data.
    • CRUD Operations
    • Aggregation Pipelines

Friday, September 6, 2024

Q1-Q5

Q1: What is MongoDB. Tell me its key features?
Q2: Give example of all NoSQL databases present. Azure service for them. 
Q3: What is MongoDB and when would you use it?
Q4: How does MongoDB achieve horizontal scalability?
Q5: What are Replica Sets in MongoDB? Why are they important?

-----------------------------------------------------------------------------------------------------------------------------------------
Q1: What is MongoDB. Tell me its key features?

Answer:
Mongo DB is a popular NoSQL database. It stores in data in JSON like document schemas. 

Key features of MongoDB
1. Document Oriented: Stores data in document similar to Json Formats
2. Flexible Schema: You are allowed to store different types of data in a same collection. 
3. Horizontal Scaling: Very good in horizontal scaling through Sharding. 
4. Indexing: Support various types of indexing for performance. 

-----------------------------------------------------------------------------------------------------------------------------------------
Q2: Give example of all NoSQL databases present. Azure service for them. 

Answer:

1. Document DB/ BSON/ JSON: MongoDB, Azure CosmosDB for MongoDB
2. Key-Value:  Redis, Dynamo DB, Azure Table Storage
2. Wide Cloumn: Hbase, Azure CosmosDB
3. Graph database: Azure CosmosDB for Gramlin

-----------------------------------------------------------------------------------------------------------------------------------------
Q3: What is MongoDB and when would you use it?

Answer:
MongoDB is a document-oriented NoSQL database designed for scalability and flexibility. Unlike relational databases, it stores data in BSON (binary JSON) documents, which allows for dynamic schemas.
From an architect’s perspective, I recommend MongoDB for use cases requiring:

1. Rapid schema evolution (e.g., product catalogs, IoT, user profiles).
2. High write throughput and horizontal scalability via sharding.
3. Polyglot persistence, where parts of the system need unstructured or semi-structured storage.
-----------------------------------------------------------------------------------------------------------------------------------------
Q4: How does MongoDB achieve horizontal scalability?

Answer:
MongoDB scales horizontally using sharding. Data is distributed across multiple shards using a shard key, and the config servers maintain metadata about data distribution.

As an architect, choosing the right shard key is critical — a poorly chosen one can lead to data skew or hot shards, causing performance bottlenecks. For large-scale systems, I’d design shard keys that balance read/write load and align with access patterns, such as a hashed key for write-heavy workloads.
-----------------------------------------------------------------------------------------------------------------------------------------
Q5: What are Replica Sets in MongoDB? Why are they important?

Answer:
A replica set is a cluster of MongoDB servers that provide redundancy and high availability. It consists of one primary and multiple secondaries. The primary handles writes, while secondaries replicate data asynchronously.
From an architect’s lens:

Replica sets ensure fault tolerance (automatic failover).

They support geo-distribution (e.g., read from nearest secondary for latency reduction).

For mission-critical apps, I’d design replication across availability zones or regions to ensure disaster recovery.
-----------------------------------------------------------------------------------------------------------------------------------------


Q6-Q10

Q6:  What is the difference between MongoDB and a relational database? Q7:  What are the limitations of MongoDB? How do you handle them? Q8:...