Getting started in back-end development
Published: 2023-02-14 05:53:47

I've spent the last few months learning about back-end development and I thought I'd share some big picture concepts to help others that want to learn. Even if it's outside of your wheelhouse, learning back-end development can give you a deeper understanding of how web applications work as a whole. It allows you to see the full picture and how front-end and back-end components work together to create a cohesive user experience. 

## Understand the purpose of relational databases
Relational databases are the backbone of most modern web applications. They are designed to store and manage structured data, and they allow developers to create, read, update, and destroy that data with ease. The key to working effectively with relational databases is to understand their purpose and how they are structured.
Relational databases are organized into tables, which are composed of rows and columns. Each row represents a single record, while each column represents a particular attribute of that record. For example, in a database of users, each row would represent a single user, while the columns would contain attributes such as the user's name, email address, and date of birth.

## Learn SQL
Structured Query Language (SQL) is the language used to interact with relational databases. As a back-end developer, it's important to have a good understanding of SQL and how to use it to manipulate data.

##Understand data relationships
One of the key concepts in relational databases is data relationships. Note that primary keys are generated when a new row of data is created. A foreign key is a reference to the primary key from a different table to establish a relationship between the two tables. 

There are several types of relationships, but the most common are one-to-one, one-to-many, and many-to-many. Understanding these relationships is crucial to designing a functional, manipulatable database.

In a one-to-one relationship, each record in one table is associated with a single record in another table. For example, in a database of employees and their job titles, each employee would have a single job title, and each job title would be associated with a single employee. This means that one table would have a foreign key column referencing a row's primary key in the other table.

In a one-to-many relationship, each record in one table is associated with multiple records in another table. For example, I recently created a to-do list where I used the tables: "Sublists" and "Tasks". A sublist has many tasks and a task belongs to one sublist. To establish this relationship, I  added a "sublist_id" foreign key column to the "Tasks" table that references the primary key column in the "Sublists" table.


Relevant schema:
Note: primary keys are built automatically and the foreign key column "sublist_id" references a specific row or data inside of the "sublists" table.

```
create_table "sublists", force: :cascade do |t|
    t.string "name"
  end

  create_table "tasks", force: :cascade do |t|
    t.string "text"
    t.boolean "priority"
    t.integer "sublist_id"
  end
```

In a many-to-many relationship, multiple records in one table are associated with multiple records in another table. Let's say an e-commerce database has two tables: "Customers" and "Products". A customer can purchase multiple products, and a product can be purchased by multiple customers. To map out this relationship, you would create a third table, "Orders", that has columns for BOTH foreign keys: "customer_id" and "product_id". Each row in the "Orders" table represents a relationship between a customer and a product that they purchased.

##Use an ORM
Object-Relational Mapping is a programming technique that maps database tables to object-oriented programming languages. An ORM allows you to work with a database using object-oriented code instead of writing SQL queries directly. This can make working with relational databases more intuitive and efficient.
In my time learning back-end development, I used Ruby which has an ORM called Active Record that maps database tables to Ruby classes. Using an ORM can simplify the process of working with a relational database and make your code more maintainable.


Thanks for reading!