How to Model Your
Data Like a Pro!
Dallas Texas, June 22nd, 2022
Bruno Martinho
Developer Advocate @ OutSystems
Why data modeling?
2
3
No “voodoo” here…
What is happening behind the scenes?
A SQL Query goes into a bar and
walks up to two tables and asks…
“Can I join you?”
4
5
Hello!
My name is Gordon Knowitall.
I’m the boss here and I’ll be running the show!
Introductions
6
Hi!
I’m NEO and I’ll be here to assist you with anything
related to the OutSystems Platform.
Introductions
7
Hey! You there… Yes, I’m talking to you!
Do you even know what this company does?
6 months… and you don’t even know what we do???
Boss is in a bad mood
This is an hotel.
If you don't want to be fired, you need to create an
application for our hotel booking system.
8
So, we have rooms...
And each room has a number, some have AC and we
classified them into Basic, Premium and Ultra-Mega-
Premium.
First requirements
The room number will be something like 101, 312 or 655.
9
From what I’ve heard it seems that Room is a great
candidate for an entity to store the room information.
Make sure that we can get the entity attributes type from
the requirements: “some have AC” this is a good
candidate to be a Boolean.
Entities and attributes
11
You know… I've been thinking…
And the room names should be different:
Silver, Gold and Diamond.
More classy…
Why doesn’t it surprise us?
12
So it seems that the room type will be a list of values.
This is a good use case to use static entities.
Also, these values might change (just now our boss
changed his mind) but the room will still have the same
type independent of the name, so we can normalize here
our model.
Static Entities and Normalization
14
Wait… Wait… Wait!
Not Diamond... Platinum is better!
Platinum shall be!
Now… who’s ready?
15
No problem here, changing the Label won’t change
anything is the application!
Static Entities and Normalization
17
Not trying to insult your intelligence…
I don't need to tell you that room numbers are unique,
right?
Obvious… but a valid one!
18
This is a very valid requirement that can be enforced with
application logic but it is always a good practice to
include it in the data model. We can use the Entity Room
indexes to achieve this.
Unique Index
20
Rooms have beds and we need to manage which beds
need to change mattress.
Regulation demands that a mattress needs to be
changed every 3 months.
More requirements…
21
This means that a Room can have multiple beds and it is
important to keep track on the last date that the mattress
has been changed. It makes sense to have another
Entity called Bed to keep this information, linked to a
Room with a 1 to Many relationship:
1 Room can have many Bed
1 to Many
23
I believe in transparency…
Let's make sure that every single room has its real photo
for our customers be able to see it.
Mr. Knowitall is the king of transparency
24
To store the room picture we need to use an attribute in
the Entity of type Binary Data. This takes a lot of
information so to improve the performance, the room
picture should be in a separate entity, the Room Picture
that can have the same ID as the Room, creating a 1 to 1
relationship.
1 to 1 and Performance
26
Now the easy part…
Our customers just need their name and passport and
they can book a room for a period of time.
Simple!
Easy is our middle name
27
In order to achieve this, it is necessary to create another
Entity to store the Name and Passport for the Customer.
Now, this Customer needs to be linked to Room. In this
case, since many Customer can book many Room, we
need a Many to Many relationship using a third Entity that
we can call Booking.
Many to Many
29
Our Booking agents reported that they are having
difficulty in seeing how many beds there are in a room.
Can you please help?
Look who’s asking gently
31
Sometimes, it is better to denormalize for performance
sake. If a screen or a server action requires many
complicated logic to retrieve the data then, performance
wise it is better to denormalize the model. In this case,
the Group by isn’t that complex, but to illustrate we can
denormalize the model and add Number of Beds attribute
in Entity Room. Don’t forget to update the number when
a Bed is created or deleted.
Denormalize for performance
33
Well, have I ever mentioned that we need this application
for our 2 different hotel brands?
Same application but we can't mix data!
Last but not least
34
In case there is a need to have data separated for
different brands or companies it is possible to use multi-
tenancy. This won’t explain deeply how this feature
works, but gives an idea that exists and can/should be
used in this use case.
Multitenancy
36
● Entities and Attributes
● Static Entities and Normalization
● Unique Index
● Relationships
● 1 to Many
● 1 to 1 and Performance
● Many to Many
● Denormalize for performance
● Multitenancy
Quick Recap
37
● Data Modeling
● Data Model - Best Practices
● OutSystems Platform Best Practices
Useful links
Thanks for your time!
38

How to Model Your Data Like a Pro!

  • 1.
    How to ModelYour Data Like a Pro! Dallas Texas, June 22nd, 2022 Bruno Martinho Developer Advocate @ OutSystems
  • 2.
  • 3.
    3 No “voodoo” here… Whatis happening behind the scenes?
  • 4.
    A SQL Querygoes into a bar and walks up to two tables and asks… “Can I join you?” 4
  • 5.
    5 Hello! My name isGordon Knowitall. I’m the boss here and I’ll be running the show! Introductions
  • 6.
    6 Hi! I’m NEO andI’ll be here to assist you with anything related to the OutSystems Platform. Introductions
  • 7.
    7 Hey! You there…Yes, I’m talking to you! Do you even know what this company does? 6 months… and you don’t even know what we do??? Boss is in a bad mood This is an hotel. If you don't want to be fired, you need to create an application for our hotel booking system.
  • 8.
    8 So, we haverooms... And each room has a number, some have AC and we classified them into Basic, Premium and Ultra-Mega- Premium. First requirements The room number will be something like 101, 312 or 655.
  • 9.
    9 From what I’veheard it seems that Room is a great candidate for an entity to store the room information. Make sure that we can get the entity attributes type from the requirements: “some have AC” this is a good candidate to be a Boolean. Entities and attributes
  • 10.
    11 You know… I'vebeen thinking… And the room names should be different: Silver, Gold and Diamond. More classy… Why doesn’t it surprise us?
  • 11.
    12 So it seemsthat the room type will be a list of values. This is a good use case to use static entities. Also, these values might change (just now our boss changed his mind) but the room will still have the same type independent of the name, so we can normalize here our model. Static Entities and Normalization
  • 12.
    14 Wait… Wait… Wait! NotDiamond... Platinum is better! Platinum shall be! Now… who’s ready?
  • 13.
    15 No problem here,changing the Label won’t change anything is the application! Static Entities and Normalization
  • 14.
    17 Not trying toinsult your intelligence… I don't need to tell you that room numbers are unique, right? Obvious… but a valid one!
  • 15.
    18 This is avery valid requirement that can be enforced with application logic but it is always a good practice to include it in the data model. We can use the Entity Room indexes to achieve this. Unique Index
  • 16.
    20 Rooms have bedsand we need to manage which beds need to change mattress. Regulation demands that a mattress needs to be changed every 3 months. More requirements…
  • 17.
    21 This means thata Room can have multiple beds and it is important to keep track on the last date that the mattress has been changed. It makes sense to have another Entity called Bed to keep this information, linked to a Room with a 1 to Many relationship: 1 Room can have many Bed 1 to Many
  • 18.
    23 I believe intransparency… Let's make sure that every single room has its real photo for our customers be able to see it. Mr. Knowitall is the king of transparency
  • 19.
    24 To store theroom picture we need to use an attribute in the Entity of type Binary Data. This takes a lot of information so to improve the performance, the room picture should be in a separate entity, the Room Picture that can have the same ID as the Room, creating a 1 to 1 relationship. 1 to 1 and Performance
  • 20.
    26 Now the easypart… Our customers just need their name and passport and they can book a room for a period of time. Simple! Easy is our middle name
  • 21.
    27 In order toachieve this, it is necessary to create another Entity to store the Name and Passport for the Customer. Now, this Customer needs to be linked to Room. In this case, since many Customer can book many Room, we need a Many to Many relationship using a third Entity that we can call Booking. Many to Many
  • 22.
    29 Our Booking agentsreported that they are having difficulty in seeing how many beds there are in a room. Can you please help? Look who’s asking gently
  • 23.
    31 Sometimes, it isbetter to denormalize for performance sake. If a screen or a server action requires many complicated logic to retrieve the data then, performance wise it is better to denormalize the model. In this case, the Group by isn’t that complex, but to illustrate we can denormalize the model and add Number of Beds attribute in Entity Room. Don’t forget to update the number when a Bed is created or deleted. Denormalize for performance
  • 24.
    33 Well, have Iever mentioned that we need this application for our 2 different hotel brands? Same application but we can't mix data! Last but not least
  • 25.
    34 In case thereis a need to have data separated for different brands or companies it is possible to use multi- tenancy. This won’t explain deeply how this feature works, but gives an idea that exists and can/should be used in this use case. Multitenancy
  • 26.
    36 ● Entities andAttributes ● Static Entities and Normalization ● Unique Index ● Relationships ● 1 to Many ● 1 to 1 and Performance ● Many to Many ● Denormalize for performance ● Multitenancy Quick Recap
  • 27.
    37 ● Data Modeling ●Data Model - Best Practices ● OutSystems Platform Best Practices Useful links
  • 28.

Editor's Notes

  • #11 Create Entity oom and scaffold Room to create a new Room Naming best practices PascalCase Meaningfull names Show actions Show properties Size (Truncate Data) Add field has Wi-FI Show that made an ALTER Table Cut/Paste will lose info!
  • #14 Normalization Static Show Data Show ER model New Scaffolding and create a new room.
  • #17 Normalization Static Show Data Show ER model New Scaffolding and create a new room.
  • #20 Indexes Show more options Try to create another room with the same number
  • #23 Show 1 to many Talk about delete rules
  • #26 Performance Show 1 to 1
  • #29 Show many to many Scafoold and create two customers Create one booking
  • #31 Show Group by
  • #33 Denormalize for performance Show on create/delete remove room update number of beds
  • #36 Multi-tenant