If you do a social network, then how should the database be arranged. I think that there are at least 4 tables:

  1. Stores id and custom settings
  2. Stores id and data (Name, surname, university, etc.)
  3. Stores id and posts on the wall
  4. Stores id and subscriptions

All tables are linked by id foreign key

Is this structure normal? If you are in the news, then after 4 tables by id takes out all the subscriptions and takes from each message from 3 tables?

    1 answer 1

    Tables 1 and 2 in your version can be combined - this is one "essence": the user.

    Subscriptions occupy a small amount and are peculiar to the User, and so far only him is interesting. After all, there will be no frequent search for "who is subscribed to X?" I would also store them in a table about the User, in a text field, separated by commas. Settings can also be shoved into one field in a serialized form.

    Total:

    1. Users (id, first name, last name, ..., subscriptions "13,15,17,19", settings);
    2. Posts (post_id, user_id, test).

    The question is, how do you want to wrap the functionality further. Groups, publics, advertising engine, applications?

    • @sergiks I did not understand about the posts, do you want to make one table of posts for the whole site? There will be a million posts. And then it will be necessary to pull out all the posts of a certain subscription - Zow
    • Million is a bit. Then expand the project to someone who understands sharding and voodoo magic. Explain what a "subscription" is. - Sergiks
    • Well, in VK / Twitter, when you click on a user "Subscribe" / "Read" his posts will appear on your page in chronological order. If you have a lot of subscriptions, these posts will be different - Zow
    • and how does this change the essence? subscription for one, anyway, that posts for the owner. And news feed, respectively - to merge subscriptions and sort them by date. - Sugar Sugar
    • And if you still have your favorites, notes, etc. They also save in the first table, separated by commas? - Zow