A
A
Anatoly602015-03-15 17:49:05
Database
Anatoly60, 2015-03-15 17:49:05

What database architecture to choose for a chat similar to VKontakte?

Hello!
Advise DB architecture for chat with history.
There is a table user , fields:

  • userId - unique id for each user in the system
  • name - username

Each user can start a dialogue with another user, you need to store the correspondence (text, date sent) and the number of unread messages. There can only be one chat between any two users. Chats are private, not group (max 2 people). Store the last 1000 messages.
You can add the interlocutor to the black list (ignore).
It is necessary to effectively, in one request, get all chats (interlocutors) for a specific user (with the exception of ignored interlocutors), sorting - first unread messages, then by the date of the last update.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Golub, 2015-03-15
@RazerVG

Well, make a table of dialogues and messages.
Messages (message_id, text, sent_date, status (read or not), dialog_id)
Dialogs (dialog_id, client_id1, client_id2)
True, a double bond is obtained. And the number of those not read is also displayed there, not a specific dialogue, but all. So just a request.
Well it is possible with only one table of the message. Where to store everything.

V
Vladimir Korotenko, 2015-03-17
@firedragon

What prevents you from creating a flat table?
user_id | co_user_id | message | isaread
select * from messages where user_id = 3456754

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question