MTV using MongoDB
Harshita Kumari
DevOps Engineer | Terraform/RHCSA/AWS/Azure Certified | AWS,Docker, Ansible, Kubernetes ,Terraform ,Python ,Jenkins,
What is MongoDB?
MongoDB is an open-source document-oriented database. It is used to store a larger amount of data and also allows you to work with that data. MongoDB is not based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data, that’s why known as NoSQL database. Here, the term ‘NoSQL’ means ‘non-relational’. The format of storage is called BSON ( similar to JSON format).
Working of MongoDB –
The following image shows how the MongoDB works:
MongoDB work in two layers –
- Application Layer and
- Data layer
Application Layer is also known as the Final Abstraction Layer, it has two-parts, first is a Frontend (User Interface) and the second is Backend (server). The frontend is the place where the user uses MongoDB with the help of a Web or Mobile. This web and mobile include web pages, mobile applications, android default applications, IOS applications, etc. The backend contains a server which is used to perform server-side logic and also contain drivers or mongo shell to interact with MongoDB server with the help of queries.
These queries are sent to the MongoDB server present in the Data Layer. Now, the MongoDB server receives the queries and passes the received queries to the storage engine. MongoDB server itself does not directly read or write the data to the files or disk or memory. After passing the received queries to the storage engine, the storage engine is responsible to read or write the data in the files or memory basically it manages the data.
MongoDB Features
- Each database contains collections which in turn contains documents. Each document can be different with a varying number of fields. The size and content of each document can be different from each other.
- The document structure is more in line with how developers construct their classes and objects in their respective programming languages. Developers will often say that their classes are not rows and columns but have a clear structure with key-value pairs.
- The rows (or documents as called in MongoDB) doesn't need to have a schema defined beforehand. Instead, the fields can be created on the fly.
- The data model available within MongoDB allows you to represent hierarchical relationships, to store arrays, and other more complex structures more easily.
Why Use MongoDB?
Below are the few of the reasons as to why one should start using MongoDB
- Document-oriented – Since MongoDB is a NoSQL type database, instead of having data in a relational type format, it stores the data in documents. This makes MongoDB very flexible and adaptable to real business world situation and requirements.
- Ad hoc queries - MongoDB supports searching by field, range queries, and regular expression searches. Queries can be made to return specific fields within documents.
- Indexing - Indexes can be created to improve the performance of searches within MongoDB. Any field in a MongoDB document can be indexed.
- Replication - MongoDB can provide high availability with replica sets. A replica set consists of two or more mongo DB instances. Each replica set member may act in the role of the primary or secondary replica at any time. The primary replica is the main server which interacts with the client and performs all the read/write operations. The Secondary replicas maintain a copy of the data of the primary using built-in replication. When a primary replica fails, the replica set automatically switches over to the secondary and then it becomes the primary server.
- Load balancing - MongoDB uses the concept of sharing to scale horizontally by splitting data across multiple MongoDB instances. MongoDB can run over multiple servers, balancing the load and/or duplicating data to keep the system up and running in case of hardware failure.
Advantages of MongoDB
- Due to Sharding, it avoids a single point of failure.
- Faster query processing due to parallel work.
- High availability through built-in replication and failover.
- Horizontal scalability with native sharding.
- End-to-end security.
- Management tooling for automation, monitoring, and backup.
Case study on MTV :
MTV Networks owns and operates hundreds of high-traffic web properties, including spike.com, gametrailers.com ,thedailyshow.com, comedycentral.com, and nick.com. These properties evolved independently using a variety of languages, Trameworks, and data models. MTV chose MangoDB as the data store for a new unitied Java-based content management system (CMS), taking advantage of its document data model and flexible schema.
The Problem
MTV's web properties were originally built on a commercial, Java-based content management system that forced their rich documents into an ill-suited data model. The team evaluated migrating to a relational model for a new CMS, but the diversity of web properties posed a major roadblock. Adding new data types and tables toe the schema significantly dampened read performance and other operations. After struggling with this architecture, which limited the evolution and success of their system, MTV began looking for a database solution that could grow, scale, and represent data flexibly as they brought additional content brands onto the platform.
Why MongoDB?
Flexibility
MongoDB's document storage mode! allows MTV to store hierarchical data (like TV episodes within a series) easily, without requiring expensive queries to build pages. MongoDB's inherently flexible schema allows MTV to concisely model the structures and data elements required by each brand.
Queries and Indexing
The rich querying capabilities of MongoDB provided a combination of features unavailable in pure key-value stores, RDBMS or the previous system. No other databases provides an efficient way to query nested content -- a hallmark of a document schema. MTV found querying nested data in MongoDB easy to understand and incredibly fast
With their previous system, all data fields had to be indexed regardless of whether they were ever queried. This led to significant wasted storage space, and unnecessary latency during updates. With MongoDB MTV can build indexes selectively, achieving high query performance and efficient use of space.
Ease of Operations
The MTV team has deep experience developing for and operating relational technologies, and found that this knowledge mapped well to MongoDB. The previously deployed system was difficult to cluster, requiring shared disk storage Tor all cluster members. In contrast, MTV found MongoDB's replica sets, which do not required shared disk storage, far simpler to scale via database clustering. With replica sets, each MongoDB server acts independently, and requires only local storage.
According to Jeff Yemin of MTV, "From an operational perspective, feels very much like MySQL, so our systems and DBA groups are quite comfortable managing the deployment.”
Results
MongoDB’s document data model enabled MTV's content management team te build a solution that can meet the needs of each of their web properties generically, while simplifying day to day operations. This lets the development team focus pa on building features for the end user instead of back-end storage.
THANKYOU FOR READING !!