Frontend developers guide to databases.

Frontend developers guide to databases.

·

8 min read

I was a front-end developer for 5 years before moving to fullstack development. As I gained experience I understood that businesses run on data and it is the only mission-critical component of the system.

This note is for an exceptional front-end developer like you looking to transition to full-stack development.

Knowledge of databases isn’t just another feather in your cap. It’s a power-up that can enhance your understanding of the data flow, improve your ability to troubleshoot issues and open up new avenues for your career.

So, let’s level up your full-stack journey and delve into databases.

Why Databases are the Heartbeat of a Web Application?

Without the database, the entire application is a static website. It’s the user-generated data that gives life to any application. Here are some points that make it the life-line of any web application:

  1. Data Storage and Management: Databases are the treasure chests of web applications, storing and managing crucial data like user info, product details, and transaction records.

  2. Data Retrieval: They’re the librarians of your application, efficiently fetching the data you need when you need it, ensuring top-notch performance and usability.

  3. Data Relationships: Databases are the matchmakers of your application, establishing and managing relationships between different data items, making complex data interactions possible.

  4. Data Security: They’re the guardians of your data, providing mechanisms for access control, data encryption, and integrity maintenance, keeping your application secure.

  5. Data Analysis: Databases are the analysts of your application, offering tools for data analysis that enable personalised experiences, detailed reporting, and more.

In short, databases keep the data flowing, powering your web application just like a heartbeat keeps the blood circulating, powering the body. As frontend developers, understanding this heartbeat is key to leveling up our full-stack game.

SQL vs NoSQL: A Quick Refresher

Mermaid Code for the Mindmap

Let’s talk about the two main types of databases you’ll encounter on your full-stack journey:

SQL

  • SQL databases are relational databases that have been around for decades. They use structured query language (SQL) for defining and manipulating the data, which is stored in tables.

  • SQL databases are well-suited for applications that require complex queries and transactions. They are also relatively easy to learn and use.

Examples

  1. MySQL

  2. PostgreSQL

  3. Oracle Database

NoSQL

  • NoSQL databases are non-relational databases that are the new kids on the block. They store data in a variety of ways, such as column-oriented, document-oriented, graph-based, or organized as a KeyValue store.

  • NoSQL databases are well-suited for applications that need to store large amounts of data or that need to scale quickly. They can be more difficult to learn and use than SQL databases, but they offer more flexibility and performance.

Examples

  1. MongoDB

  2. Cassandra

  3. Redis

The best database for your application depends on the specific requirements and challenges of your project.

When to choose what?

Here’s a comparison table that can help in deciding between SQL and NoSQL databases based on various conditions:

A shallow comparison of SQL vs NoSQL

Please note that the choice between SQL and NoSQL databases should be based on the specific requirements of your project.

It’s also possible to use both types of databases in a single application, if necessary. In e-commerce apps generally, user profiles are stored in NoSQL databases, while the Cart and Checkout are in SQL databases.

Important Concepts to Know in SQL

  1. Complex Queries: SQL allows for intricate queries that can join data from multiple tables, filter records based on complex conditions, and perform calculations on the data. Understanding how to write complex queries can help you extract the exact data you need from your database.

  2. Database Normalization: This is a process used to organize a database into tables and columns to reduce data redundancy and improve data integrity. It’s essential for maintaining a well-structured and efficient database.

  3. Indexes: Indexes are used in SQL databases to speed up the retrieval of data. They work similarly to an index in a book and can make your database queries significantly faster.

  4. Transactions: A transaction is a single logical unit of work that accesses and possibly modifies the contents of a database. Transactions in SQL ensure that the database remains in a consistent state even in case of system failures.

  5. Stored Procedures: These are prepared SQL codes that you can save and reuse. Instead of writing the SQL command every time you want to perform the task, you can call the stored procedure.

  6. Triggers: A trigger in SQL is a special type of stored procedure that is executed when an event occurs in the database. Triggers are used to maintain the integrity of the data in the database.

  7. Views: A view is a virtual table based on the result-set of an SQL statement. Views allow you to encapsulate the logic of your queries, making them simpler to write and read.

The Complete SQL Bootcamp for the Manipulation and Analysis of Data | Udemy { not sponsored }

Important Concepts for NoSQL Databases

  1. CAP Theorem: This theorem states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees: Consistency, Availability, and Partition tolerance. Understanding this theorem is crucial when designing and working with NoSQL databases.

  2. BASE Properties: NoSQL databases often follow the BASE (Basically Available, Soft state, Eventually consistent) model, which is a contrast to the ACID properties of SQL databases. Understanding the trade-offs between ACID and BASE can help you make better decisions when designing your database.

  3. Data Modeling: Unlike SQL databases, NoSQL databases do not require a fixed schema. Understanding how to model your data effectively in this flexible environment is key. This often involves understanding concepts like denormalization and data duplication.

  4. Scaling: NoSQL databases are designed for horizontal scaling, which involves adding more servers to handle more traffic. Understanding the principles of horizontal vs. vertical scaling can help you design more scalable applications.

  5. Replication and Sharding: These are techniques used to distribute data across multiple servers. Replication involves making copies of the data, while sharding involves dividing the data into different parts. Understanding these concepts is important for ensuring data availability and performance.

  6. Consistency Levels: Different NoSQL databases offer different levels of consistency, from strong consistency to eventual consistency. Understanding these levels and how they impact your application is important.

  7. Indexing: While NoSQL databases do not have the same structured query language as SQL databases, understanding how to index your data can still improve query performance significantly.

  8. Data Types: Many NoSQL databases support a variety of data types, including document, key-value, wide-column, and graph. Understanding the strengths and weaknesses of each can help you choose the right type for your application.

  9. Query Language: While NoSQL databases do not use SQL, many have their own query languages that you’ll need to learn. For example, MongoDB uses a method-based query language that’s quite different from SQL.

  10. Concurrency Control: Understanding how your NoSQL database handles concurrent operations is important. Some NoSQL databases use lock-based systems, while others use optimistic concurrency controls.

  11. Fault Tolerance: NoSQL databases are designed to handle failures gracefully. Understanding how your database handles node failures, network issues, and other problems can help you build more robust applications.

  12. Security: While NoSQL databases may not have the same granular permission controls as SQL databases, understanding how to secure your data is still crucial. This includes understanding how to encrypt data, manage user permissions, and protect against injection attacks.

  13. Transactions: While traditional ACID transactions aren’t always supported in NoSQL databases, some do offer transaction-like functionality. Understanding how these work can help you maintain data integrity.

  14. Data Aggregation: Many NoSQL databases offer powerful data aggregation frameworks. These can be used to perform complex data analysis and transformations, similar to what you might do with SQL’s aggregation functions.

Technologies to interact with a Database?

Now that you have learnt the fundamentals of a Database it’s time to interact with your DB using these technologies:

  1. ORMs: Object-Relational Mapping, or ORM, is a technique that lets you interact with your database like you would with SQL. In other words, it allows you to manipulate and access your data as objects and properties in your code, without needing to write SQL commands.

  2. Database Management Systems (DBMS): These are software applications that interact with the user, other applications, and the database itself to capture and analyze data. Examples include MySQL Workbench, Microsoft SQL Server Management Studio, and phpMyAdmin.

  3. Database Drivers: These are libraries that provide a way for applications to interact with specific databases. They handle the details of the database protocol, converting your application’s requests into a format the database can understand.

  4. Connection Pools: A connection pool is a cache of database connections maintained so that the connections can be reused when needed by a server. It can dramatically reduce the overhead of establishing a new connection for every user request.

Each tech is used differently in different use cases. If you are a backend engineer you’d mostly work with drivers or ORMs.

So, it's important you read some blogs or use Chat-GPT to quickly understand each one of them, to understand what tech to use when.

  1. Database Design for Mere Mortals: 25th Anniversary Edition, 4th Edition [Book] (oreilly.com)

  2. PostgreSQL: Up and Running

  3. Scaling MongoDB

  4. https://www.youtube.com/watch?v=4cWkVbC2bNE

GitHub - manjunath5496/Database-Books: "Computing should be taught as a rigorous - but fun …
"Computing should be taught as a rigorous - but fun - discipline covering topics like programming, database structures…
github.com

What’s Next?

Follow pages, profiles and join communities of specific technologies.

Discuss things that you don’t understand and ask people about real life experiences with Databases.

The more you connect with people the easier it gets to learn things.


If you got a direction on where to start let me introduce myself.

I am Sagar, I am an architect at Mckinsey and Company. I help the world’s best companies build better software.

I talk about advanced topics and help people move into Fullstack Engineering.

Join my 400+ super dev community on Twitter. Here's my introduction.

Did you find this article valuable?

Support Sagar by becoming a sponsor. Any amount is appreciated!