Skip to content

database erds

Shaylen edited this page Apr 17, 2023 · 1 revision

Database Entity-Relationship Diagrams

Initially when I broke down the database into micro-databases, I decided to flatten [denormalize] the databases in order to negate the idea of temporal coupling

What that means in this context is one microservice having a dependency on another in order to complete a transaction

For example, in order to complete an order, the following is needed:

  • Customer info from the customers api
  • Address info from the addresses api
  • Tyre info from the tyres api for each order item

If it wasn't flattened, then at the orders api when a POST request is made, it would need to make downstream calls to those apis to complete the transaction, which in turn would significantly reduce response time, and invites a whole set of other issues like:

  • Authentication to the downstream microservices [needs token exchange again]
  • Possibility of downstream microservices being down, eventually leading to failure after a long wait period

I'm pretty sure I'm a little naive in this subject, but one thing I did to improve the performance of the flattened databases was to add non-clustered indexes on the columns that would have been the primary key in its own table

The DbContexts I'll add Entity-Relationship Diagrams for, are the ones that I created, not the ones provided by IdentityServer4 or AspNetCore Identity

AddressDbContext | SeelansTyresAddressDb

erDiagram
    Address {
        guid Id PK
        string(100) AddressLine1
        string AddressLine2
        string(100) City
        string PostalCode
        bool PreferredAddress
        guid CustomerId "Has a non-clustered index"
    }

Loading

OrderDbContext | SeelansTyresOrderDb

erDiagram
    Order {
        int Id PK
        datetime OrderPlaced
        bool Delivered
        guid CustomerId "Has a non-clustered index"
        string FirstName
        string LastName
        string Email
        string PhoneNumber
        guid AddressId "Has a non-clustered index"
        string AddressLine1
        string AddressLine2
        string City
        string PostalCode
    }
    OrderItem {
        guid Id PK
        int Quantity
        guid TyreId "Has a non-clustered index"
        string TyreName
        decimal TyrePrice
        int OrderId FK "Has a non-clustered index"
    }

    Order ||--|{ OrderItem : has

Loading

TyresDbContext | SeelansTyresTyresDb

erDiagram
    Brand {
        int Id PK
        string Name
    }
    Tyre {
        guid Id PK
        string(40) Name
        int Width
        int Ratio
        int Diameter
        string(40) VehicleType
        decimal Price
        bool Available
        string ImageUrl
        int BrandId FK "Has a non-clustered index"
    }
    Brand ||--o{ Tyre : makes

Loading
Clone this wiki locally