The whole video was special. You are a TOP G. Keep it up bro
@DatabaseStar Жыл бұрын
Thanks!
@codexperience7951 Жыл бұрын
nice erd for chat systems, will use yours and enhance it base to what i needed. thanks to your video
@DatabaseStar Жыл бұрын
Glad I could help!
@ymahtab10 ай бұрын
Hi, great video as always. One question: in the message table, why do we need to distinguish from_number and to_number from contacts? We could have from_contact_id and to_contact_id as FKs to the contact table. I feel like one table you're missing is a user's contact list (probably need a joining table) which would let the application figure out if the message was sent to a phone number or a saved contact. Does this make sense? EDIT: ok I think you covered this at around 4:30. We want to distinguish the contact's number from the recipient number the message was sent to at the time.
@DatabaseStar9 ай бұрын
Good question, yeah that's right!
@gabrielcosta11592 жыл бұрын
Hey man, nice video! I'm new to this database thing, so I got a question that might be a bit stupid hahaha. If I want to send a message to only one contact, how would that work since the table contact is only linked directly to the table "group_member"? I mean, I would have to use the "group_member" table even when the message is not sent to a group, right? I'm kinda confused :x
@DatabaseStar2 жыл бұрын
Hi Gabriel, good question! Yes I think it would use the same concept, even if it is just to one contact. The group would have just the one contact.
@gabrielcosta11592 жыл бұрын
@@DatabaseStar Oh ok.. Thank you so much!
@shankhashubhradas1586 Жыл бұрын
I also got the same doubt. Thanks @gabrielcosta1159 for asking and @DatabaseStar for answering 👍
@NadjibSamsung8 ай бұрын
I think this design is vulnerable. Because any authenticated user can alter the value of the sender id. The solution is to verify that the value of the sender id is the same value of the user id stored in the sessions store.
@DatabaseStar8 ай бұрын
Good point. This is just the database and there would be more involved in the application on authentication and ensuring people can only do the things they need to do. There would be no way for a user to edit IDs in a table.
@johnnychin95983 ай бұрын
Sir, do you have a video were in the product item have different price depending on the customer. Say
@DatabaseStar3 ай бұрын
I don't have a video for that, but you could enhance an existing database to do this.
@sidforreal Жыл бұрын
Why contact and group_member is not a many to many relationship? One group can have multiple contacts, and one contact can be present in multiple groups
@DatabaseStar Жыл бұрын
That's a good point - it should be many-to-many actually. And therefore it would need a joining table between the two. Thanks for pointing it out.
@Иван-д6ф6с3 ай бұрын
Hi, could you please extend your tutorial to include case how do you go about handling "media" attachments, "last seen", "read by" please.
@DatabaseStar3 ай бұрын
Good idea!
@idkanymoreman2 жыл бұрын
awesome stuff.. thanks for the clear explanation.. one question.. as the table grows, wont it be slower to query and fetch the chat messages if we store them in one table?
@DatabaseStar2 жыл бұрын
Good question. It would get slower eventually, but databases are very good at handling large amounts of data. A table with a million rows is quite manageable, for example. You can also add indexes, and other performance improvements, to help your queries.
@thebulletkin8393 Жыл бұрын
In the group_member table, I thought every record would need to have a primary key in order to be uniquely identifiable, but that table only has two foreign keys. Do those keys also serve the same purpose as a primary key then?
@DatabaseStar Жыл бұрын
Good point! Yes the combination of both columns should be unique. This could be done as a primary key (both columns would be included in the primary key) or as a unique constraint.
@jatinsutaria7992 Жыл бұрын
Good stuff. However, how would you deal with figuring online users who need to be send messages to? Also, offline users, when they get online - how would this design help dispatch the missed messages to these users?
@DatabaseStar Жыл бұрын
I think regardless of whether they were online or offline the message would still be stored in the system. Perhaps there could be some code in the application to display all messages since the user last logged in and show them as new messages. I don’t know how you would determine if a user is online or offline though.
@lost-mar-ble4 ай бұрын
I dont understand this towards the end...how can contact and group member have one to many relationship?
@DatabaseStar4 ай бұрын
Good question. It’s because a contact can be in multiple groups in a chat application. A group for family and a group for their sports club friends and a group for other friends, for example.
@acbusiness2023 Жыл бұрын
Really impressed... love this stuff...
@DatabaseStar Жыл бұрын
Thanks!
@BaoNguyen-yg3vp2 жыл бұрын
With messages being stored persistently and the above relational data model. Which database is most suitable for chat app?
@DatabaseStar2 жыл бұрын
I’m not sure. You could get started with any sql database and it should work, I think.
@palspal2329 Жыл бұрын
Are u sure a sql db would be fine for this usecase?
@DatabaseStar Жыл бұрын
Yes it should be fine to use for this kind of design.
@practicalbong1497 Жыл бұрын
if we want single user to send a message and or send to to a group how will i do that here ?
@DatabaseStar Жыл бұрын
To do that, you would add a record to the message table with the details of the message, with a link to the conversation. This conversation could have one or many people in it.
@rockon74782 жыл бұрын
I am wondering if this database design was for the on-device database like of watsapp or for the central hosted database ??
@DatabaseStar2 жыл бұрын
The idea was that it would be the central hosted database, but the on-device database could be different.
@thongnguyen73542 жыл бұрын
How do i differentiate single chat and group chat? tks
@DatabaseStar2 жыл бұрын
This design assumes that a chat is the same regardless of how many participants. It could have two people (a single chat between two people) or three or more (a group chat).
@thongnguyen73542 жыл бұрын
@@DatabaseStar Thank you for answering my question, so how can I tell the difference?
@rahulraj94391 Жыл бұрын
@@thongnguyen7354 get the count, if count. > 2 - it means it is a group else - it is a converrsation between only 2 people. Select Count(conversation_name) from conversation where conversation_id = "REQ ID".
@sandiladhikari79034 ай бұрын
@@thongnguyen7354 for starters, you could see how many contact_id are there in group_member table, if its just 2, then its a single chat, if more than 2, the its actually what we generally understand as a group. Basically single chat between two people is also a group with only two participents. That is the concept. You could tell the difference only looking at participents. On a second approach, I don't see anything wrong with two table system for single chat and group chat feature.
@aalzahrani9271 Жыл бұрын
I have three users and each user has a table. How will I do that here ?
@DatabaseStar Жыл бұрын
Is there a way you can use a single table for all of your users, and each of the users have separate IDs? If not, then you could relate each of the three user tables in the same way as you see the user table in this design. It wouldn't be as robust, because you would have three foreign keys, each to a different table, but it could work.
@aalzahrani9271 Жыл бұрын
@@DatabaseStar What about creating users table as superclass and the other three tables that have been created will be subclasses?
@ron-952 жыл бұрын
hey can you make bridge table with 2 EAV data model?
@DatabaseStar2 жыл бұрын
Yeah you probably can!
@falseloop Жыл бұрын
What about temporary like 24hr story system
@DatabaseStar Жыл бұрын
You could add a status for each message to store whether it has expired (past the 24hr timeframe) or permanent. Or you could have the application calculate it based on the time it was sent.
@medilies2 жыл бұрын
In this case how to identify the sender?
@DatabaseStar2 жыл бұрын
You can match the message.from_number to the contact.phone_number to see who the sender is.
@john-zu3uo2 жыл бұрын
Thanks for this video sir!!
@DatabaseStar2 жыл бұрын
Most welcome!
@take_a_lunch2 жыл бұрын
Will searching or filtering messages slow down if more than a 100,000 messages are inserted into the database? What are the consequences of this, and how can it be resolved?
@DatabaseStar2 жыл бұрын
I don't think it would slow down. Databases are designed to handle large amounts of data, and even if you had millions of rows, the performance would still be manageable. You could use indexes to ensure the data can be filtered if needed, and there are other database-specific features that could be used.
@take_a_lunch2 жыл бұрын
@@DatabaseStar ohhhh....そか
@fuddyduddy2 жыл бұрын
@@take_a_lunch Don't pretend to be a Japanese. Chinese.
@nirajpatil23262 жыл бұрын
@@fuddyduddy damn 😂😂
@iremozen71722 жыл бұрын
that is a great video!! thank you. could you make a video for a simple delivery application?
@DatabaseStar2 жыл бұрын
Thanks! What do you mean by a “simple delivery application”? Like a food delivery service or something else?
@iremozen71722 жыл бұрын
@@DatabaseStar exactly, food delivery app would be awesome
@Asurow Жыл бұрын
what if Message table have message_id, message_text, from_contact_id , to_contact_id, send_datetime and Group_member_Id fk . Group_member table have Group_member_Id , message_id fk and Contact_id fk.
@DatabaseStar Жыл бұрын
Yeah, that could work, but I think it would only allow a message to be sent to a single contact.
@juhairahamed53422 жыл бұрын
Good explanation
@DatabaseStar2 жыл бұрын
Thanks!
@eugenefedorov3498 Жыл бұрын
But it will be a crazy query to get only 20 last msgs for specific conversations id, as it will need to filter a table from millions and millions other msgs. I dont know the right way right now, only know few with some pros and cons. Save all msgs as a json in field. But then it will be really hard to write new msgs each time. Other idea is to create for each conversations new table. But then it means we will have millions of tables in data base. But still i think this is the best aproach.
@DatabaseStar Жыл бұрын
That's good you're considering other options. The query itself won't be too crazy. It would be something like this (in MySQL): SELECT message_id, from_number, message_text, sent_datetime FROM message WHERE conversation_id = X ORDER BY sent_datetime DESC LIMIT 20; The database shouldn't have an issue looking through millions of messages if you have an index on the conversation_id column. If it does, you can then look into other performance strategies.
@yertayyeras61602 жыл бұрын
So sorry, but I think it is bad design for chat. Because you wanna say, If I wanna open message list who wrote me or I, I need to check only column from_contact? but if another person wrote me, how should I get it?
@DatabaseStar2 жыл бұрын
Thanks for the feedback! If you want to see the list of messages that were sent to you, you can query the message table. If you want to display a list of your conversations, like the main screen in WhatsApp, you would query the conversation table and perhaps the contact table. If you want to see the messages in the conversation, you would query all tables but most of the data would be in the messages table.
@yertayyeras61602 жыл бұрын
@@DatabaseStar thank you for the explaining. But I have one question. What need to do, when one of the user deleted chat. It means this user deleted chat only for him/her. But second user should see old messages. Because first user deleted only for him/her sef
@DatabaseStar2 жыл бұрын
Good question. It would depend on how you want the application to behave. If you want to have this functionality, you could add a field to indicate whether the chat is deleted or hidden for a particular user. The chat would still exist, so other users can see it, as you mentioned.
@yertayyeras61602 жыл бұрын
@@DatabaseStar ohh, I got it. You didn’t add this functionality? It is my bad, I thought you added also this part, and I tried to understand that part, because, in my project I need this lol