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.

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


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

No comments:

Post a Comment

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:...