Entity Relationship Diagrams
Tags: database, codenewbie, productivity, programming
Published: 2022-09-19 07:23:18

I remember the first time I purchased items from an e-commerce website - A 32GB flash drive, a boombox and a tripod - I did it with my phone. Pop-ups, redirects, eternally loading pages, having to type my card details and all those triggering experiences. However, nothing trumps the anxiety of waiting for the items to be delivered immediately after payment. I know you can relate. 😂

![Waiting for delivery meme](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ug7850qusj1x46n4uli.png)

I didn't quite understand the process, but the website was functional. I got my items delivered as scheduled. They looked nothing like what I paid for on the website. Yes, you are right! The no return, no refund policy. I couldn't return the items or get a refund. Moreso, replacing them would have been such a drag. I just had to keep them. 🤷🏽‍♂️

I'm a junior backend engineer now, and I appreciate the thought and work put into creating these applications. 

Apps have complex systems that comprise different entities interacting with one another. 

Think about how your favourite e-commerce platforms process millions of orders from millions of people around the world by the second. Crazy, right?! These operations are so effective that users trust and recommend them to others. 

Software engineers have to visualize the entities involved using an Entity Relationship Diagram or Model to implement these complex features.

### What is an Entity Relationship Diagram?
ER Diagrams are used for relational database design to illustrate how entities and their attributes interact within a system.

![Entity Relationship Diagram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmm5mzen3of6t4eue1qw.png) _[Image Source](https://d2slcw3kip6qmk.cloudfront.net/marketing/pages/chart/seo/ERD/discovery/erd-school.svg)_

### How it Started 
Many principles we apply today can be traced back to the works of Aristotle. Nevertheless, some brilliant minds have made their marks in the world of technology.

![Peter Chen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/799jpeyihc2g6mc8iijc.png) [_Image Source_](https://www.csc.lsu.edu/~chen/peterchen.jpg)

In 1976, Peter Pin-Shan Chen published a seminal paper titled "The Entity-Relationship Model: Toward a Unified View of Data." He is renowned for creating entity relationship modelling for database design. James Martin, the Father of CASE, added ERD refinements. 

The Computer-Aided Software Engineering (CASE) process helped automate defining a data dictionary directly from the description of a business process. This automation marked a milestone in modern business software engineering.

### Components of an Entity Relationship Diagram

- **Entity:** This includes anything that you can define. Think of nouns like people, products, events or anything with data.

![Example of Entities](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jymbmjdz56ujt8sytw82.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/Examples%20of%20Entities.png)_

Entities can be in types, sets, or categories. For example, electronic appliances would be an entity type. Entity sets are like entity types but also include an element of time. An example could be the iPhones ordered yesterday.

- **Relationship:** This refers to how entities interact with one another. Think of relationships as a verb. Take for instance, users signup for newsletters.

![Relationship](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7z4f2bnnumw6fw2u50z2.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/Relationship%20Examples.png)_

- **Attribute:** This refers to the data that qualifies the entities. For example, name, age and phone number. Think of attributes as adjectives. 

![Attribute](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w0t26xlk4losxfxg6mom.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/Attribute%20Examples.png)_

- **Cardinality:** This represents the numerical attributes of the relationships between entities or entity sets.

![Cardinality](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wrtibh0618royuyv6hd.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/ERD%20Lines%20Examples.png)_

### How To Draw a Basic Entity Relationship Diagram

**1. Purpose** 
Understand the purpose and scope of the system you intend to design.

**2. Entities**
Enumerate the entities involved. Map them out in different rectangles as you see fit.

![Entities in ERD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvdf1waquvogsg0zjmku.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/HowtoERD1.png)_

**3. Attributes**
Factor in more details by adding attributes of the entities. 

![Attributes in ERD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rdipwjwbxwo5pbea952v.png)  _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/HowtoERD2.png)_

**4. Relationships**
Consider the relationships within your system. One way to do this is by answering this question, what does the ___ do with the ___? The customer purchases the car. The student signs up for the newsletter, and so on.

![Relationships in ERD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pcx7jauo9c8qciwxmq2.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/HowtoERD3.png)_

**5. Cardinalities**
The notations help your ERD reader to understand the interactions between the entities. At a glance, they will know if there are zero, one, many, or some combination of those interactions.
![Cardinalities in ERD](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b8l7j1l9rxmtgdz01w14.png) _[Image Source](https://www.gliffy.com/sites/default/files/image/2020-10/HowtoERD4.png)_

**6. Save**
You can save and export the file.
![ERD complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/is199uv74d2gaies81vf.png) _[Image Source](https://www.gliffy.com/blog/how-to-draw-an-entity-relationship-diagram#why-draw)_

Now, I am beginning to understand what happens when I use applications. I am most definitely less critical. 😅

Happy coding! 🖤


### Resources
1. [A Short History of the ER Diagram and Information Modelling](https://www.dataversity.net/a-short-history-of-the-er-diagram-and-information-modeling/)
2. [Entity Relationship Diagram - ERD](https://www.techtarget.com/searchdatamanagement/definition/entity-relationship-diagram-ERD) 
3. [ER Diagrams](https://www.lucidchart.com/pages/er-diagrams)
4. [How to Draw an Entity Relationship Diagram](https://www.gliffy.com/blog/how-to-draw-an-entity-relationship-diagram#why-draw)
5. [What is Entity Relationship Diagram](https://www.gliffy.com/blog/what-is-entity-relationship-diagram)

_[Cover Image Credit](https://www.freecodecamp.org/news/content/images/size/w2000/2022/08/guerrillabuzz-crypto-pr-IlUq1ruyv0Q-unsplash.jpg)_