Frontend developers guide to databases.
I was a frontend developer for 5 years before moving to fullstack development. As I gained experience I understood that businesses runs on data and it is the only mission critical component of the system.
This note is for an exceptional frontend developer like you looking to transition to fullstack 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 makes it the life-line of any web applications:
- 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.
- 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.
- Data Relationships: Databases are the matchmakers of your application, establishing and managing relationships between different data items, making complex data interactions possible.
- Data Security: They’re the guardians of your data, providing mechanisms for access control, data encryption, and integrity maintenance, keeping your application secure.
- 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
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
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
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:
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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Recommended Course
The Complete SQL Bootcamp for the Manipulation and Analysis of Data | Udemy { not sponsored }
Important Concepts for NoSQL Databases
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Recommended Course
Technologies to interact with a Database?
Now that you have learnt the fundamentals of Database it’s time to interact with your DB using these technologies:
- 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.
- 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.
- 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.
- 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, its important you read some blogs or use Chat-GPT to quickly understand each one of them, to understand what tech to use when.
Recommended Reading for Absolute Beginners
- Database Design for Mere Mortals: 25th Anniversary Edition, 4th Edition [Book] (oreilly.com)
- PostgreSQL: Up and Running
- Scaling MongoDB
- https://www.youtube.com/watch?v=4cWkVbC2bNE
Important Links for Database Knowledge
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 softwares.
I talk about advanced topics and help people move into Fullstack Engineering.
Join my 400+ super dev community by on Twitter.