all the types of data

WebDev Starter Pack - Where lives the data in the World Wide Web - Databases and its concepts SQL and NoSQL!

By Eroshi | devnewbies | 1 Aug 2020


Hello guys, that's Eroshi in another round of Web Development starter tips! Today I'm going to overview about how websites store its data around the WWW!

Every day in our life we spent a lot of time-consuming data, this is common, you came to Publish0x and read some article or go to your Instagram or Twitter or even access Banano Discord :P and as a user we don't think about HOW... HOW or WHERE this data lives? Where your picture in the Facebook since 2011 lives, how a front-end knows your data, and how did they get it? 

All this questions is really common if you are a curious guy and if you are a web developer you already know the answer... All the data in the World Wide Web lives in Databases, no wait, the answer was in the title all the time 😲. Ok no jokes anymore.


What is a Database

Database is the place where all the data come and go. We use back-end languages to call the database such as NodeJS, python, Java, C#, whatever this kind of programming languages has its own way to connect to a database and run into a web server as I said in this article. So in this way each website as publish0x has a database configuration to get your article for example and print in the front website to everybody sees it!

But the world of database has been distinguished in two main parts nowadays, each part has particularities that I will talk about and this is the main way to store data as a web developer, you'll need to define what kind of database you'll need in each particular application/project you have.


Type of Databases

There is two main types of databases nowadays:

  • SQL - Structured Query Language - Relational Database

SQL is the main language to do "queries" inside a database called by itself as Relational Database!

So a relational database look likes a lot a big excels plain... You have data and the kind of data you'll need, but SQL works in a structured way, it'll work like a programming language that will select data that you need inside a plain, for example: A user logged in a website, so now the back-end will go to your database and get all the data about its user, so it'll authenticate him inside the website. This is really important way to understand normally all the data stored in the worldwide...

3179ec24cd229dfbb346213cda9e572982d386ddab2f546d6dec53a0307da8b2.png

Your SQL will need to be structured in a UML when you are thinking your system, as the picture above. This picture shows you a one to main relationship between two entities: City and Address... Yes a bit hard to understand if you don't know much about but is just an overview though!

Now this is an example of a raw pure SQL, you will select * from employees where name like "%rercules%", this will be asking inside your database about any name that has "rercules"! So if you see in the results below will have the "identify" about the employees in the image below.

977fcbb168ae2dfeaa593a239ef2f86161d34d6c0a65d5a8f39b54925211e73a.png

 

Relational Databases has a lot of concepts with a great architecture, but mainly:

  • Tables - Each table inside an SQL is an entity of your business rule, for example: Table User and Table Store
  • Relationship - There is relationship between tables, for example: A user bought 2 items in a store, here we have a kind of relationship between tables/entities: user, item and store, so each one has your data inside the table.
  • There is 3 main kinds of relationship: One to One, One to Many, Many to Many, each one has a signification concept to understand, I will not focus, but this will be following you all the way if you are a web developer.

SQL is a real tricky because Relational Databases was created inspired by relational algebra(Math) but is the first and the most used database, it's the main way to be a DBA - Database Manager, a man who just worked with a database. But nowadays web developers has been working even more with the database. If you need big relational transactions with scalability and cheap database services to use, SQL will deal better with your economy. Of course there is a lot more that SQL can really deal better.

SQL Clients

SQL has clients to developer and work with, this is the most famous:

 


  • NoSQL - Not Only SQL

Since the beginning of the WWW how we store data is important, and SQL handles perfect when we have transactions between a lot of data but sometimes is not so fast in a data stream; if you are willing to spend a bit more and your project is not so complex in architecture, but in an incredible fast way to deal with data, you'll can use NoSQL database.

Non-Relational databases(or Indexed databases) has been the hype in the last years, is easily to understand and learn... If you know about JSON will have not many problems to understand this concepts that are different from Relational Database:

939f3119af31c18169fd783a41dd18ae8bf02ba8b685f69cdfe787470beff1e4.png

  • In SQL, we have tables, but NoSQL we have collections (in MongoDB case).
  • In SQL is relation between tables, but NoSQL has index between collections.
  • SQL has rows but in NoSQL we have documents.

Also in NoSQL has another types instead this I showed before:

d778a73632c8debaa9f40143a6c055de8be4efde2c972759888ccb89b249e273.png

So there are another ways to store data inside NoSQL databases, but the most common is this two: key-value and document concepts; these concepts is the most popular but it's up to you in choosing what NoSQL technology will work with.

So let's have a deep dive in how NoSQL shows data to developers:

1236025369e0b4cd95cc967d43da7861959df5052d1227cbd56d1540f922d2d7.png

This is how a BSON works, MongoDB is one of the most popular NoSQL nowadays, and this pic above is the main way that data is arranged to developers understand... This BSON has an _id, with username and there is embedded sub-document, a kind of deep level with more data inside the BSON... If you already worked with JSON before will know how a BSON works, in this case then you can choose your back-end server, use MongoDB as your NoSQL server(can use MongoAtlas to host in the cloud yours data) so you can mount your article looking in a NoSQL way!

2577f5d72f725dd2b2b2152ddee8becf275e3cf7d6c81c1a73a5a8efce3c1bbb.png

This is how Compass (a MongoDB client) shows data, then you can see the "filter" part, there is {Country:"Brazil"}. This is showing how you can use mongo to find data inside the Mongo collections! Really easy, then you can choose your back-end server language as NodeJS, Java, Python, C# or whatever back-end programming language you work with and find the right package that consume MongoDB data and way to go!

 

NoSQL Clients:


When to use SQL or NoSQL?

It's all depends on the development use for the data's flow inside your application... If you have a fast development you can go with a simple Sqlite3 or work around with Redis, but don't use SQLite in production environment if you have a really heavy charge request to the database, because it won't have the support to heavy charge, so using Redis is way better and is fast because is an in memory database, but just if your business rule is really simple as using inside a telegram bot for example, Redis as NoSQL is fast and can store JSON directly using strings.

If you have big transactions in your business rules, as an e-commerce you can choose PostgreSQL, an SQL that can store JSON data though, so you can use the power of NoSQL with SQL, instead I have never used PostgreSQL before, I prefer to work with MySQL although it hasn't JSON adapter inside, is more famous.

This all depends on how the developer/DBA will prefer to choose, normally both can be used in the same project, this is not a rule!


 

Guys that's it I tried to give you all an overview and explains about this two main concepts in web development world nowadays, I hope everyone likes! :)

Thank you!

How do you rate this article?

5


Eroshi
Eroshi

Front end developer and Crypto evangelist, but not finacial advisor! Follow me in twitter: @andrecrjr


devnewbies
devnewbies

Web development, Front-end, Telegram Bot, Javascript in a newbie way, follow me to good development things!

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.