Types of Databases

Database

Over the years, there were many competing approaches to data storage and querying. The oldest and best-known database is a relational database, where the data is organized into relations called a table. To overcome the drawbacks of Relational Database like scalability, a document model database is introduced the term NoSql got famous. The term NoSQL represents all databases that are not Relational Databases. NoSQL itself has many types of databases that is what we are going to see now.

1. Relational Database

This is the oldest form of data storage, here the smallest persona in data is considered as a table. For example, we have to represent data of students, teachers, and the course. Here we will have 3 tables for students, teachers, and the course.

Where each row inside a table considers as an individual entity. Each row inside a student table will represent a student and his/her details.

Example – MySql, Postgres

Pros:

  1. Works for almost every scenario
  2. ACID-compliant
  3. Allow us to fire complex queries

Cons:

  1. Scalability
  2. We should know the schema beforehand, not suitable for unstructured data.

2. Key-Value Pair

Redis
Redis

This is one type of NoSql, here the data is stored in the format of key-value pair. It’s like HashMap of java or Dictionary in C#, python. The most common use case is, these databases are used as caching layers as data is stored in memory in form of key-value pair.

Example: Redis, Memcached

Pros:

  1. Fast access
  2. Best for caching

Cons:

  1. Limited Space
  2. No complex queries can be performed
  3. Not persistent, because data are stored in memory

3. Wide Column Database

Cassandra

A wide column database is an extension of the Key-Value pair database, where the data is stored in the form of a key and a group of columns. Key -> { column1, column2 }. Mostly used for time series data like logging or where writes to the database is high

Example: Cassandra, Apache Hbase

Pros:

  1. Schemaless
  2. Scalable and Replication can be done easily.

Cons:

  1. Not suitable high read scenarios
  2. No Joins

4. Document Model Database

Mongo DB

Here the data is stored in the form of documents, each document will have information in the format of key-value pair, it is schema-less, well some library allows us to enforce schema to the DB but in it true self it is schema-less.

Example: MongoDB, CouchDB

Pros:

  1. Suitable for unstructured data
  2. Schemaless
  3. Easy to scale
  4. Suitable for hierarchical data storage

Cons:

  1. No ACID-compliant
  2. Joins are headaches here!

5. Graph Data Model

Here the data are represented as nodes and the relation between them as edges

Graph Database

Example: Neo4j

Pros:

  1. Suitable for Knowledge graph
  2. Recommendation Engine

Cons:

  1. Hard to visualize complex data.

6. Search Databases

Elastic search

Here the data is stored in the form of documents but along with that, the database has an inverted index for fast search. An Inverted index is like an Index behind a book. For a given word we can find all the documents which has this word.

Inverted Index

Example: Elastic Search

Pros:

  1. Used for fast search
  2. Suitable for searching and typehead.
  3. Fuzzy Search is possible
  4. Scalable

Cons:

  1. Solves problem for small use case, cannot be used as primary database like mongo DB

7. Multi-Model Database

Here we use multiple databases to achieve our use case with the help of APIs. An example of such a database is GraphQL. https://graphql.org/

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *