I make a system that includes a tape of ads . User subscribes to several categories. Then he is given a news feed from all categories for which he is signed: I described the following architecture for this: enter image description here

But I understand that to get the "Ribbon", I must first get a list of all categories for which the user is subscribed, and only then request data from the Posts table.

Generally how much is the right decision? Maybe somehow you can build an architecture to get the tape in one request ?

  • SQL is a very powerful thing. It allows almost any data from any number of tables in any section to get a single query, especially if the database structure is normalized (like you). If it seems to you that some information cannot be obtained in one request, it means that you need to study SQL more deeply :) - Mike

1 answer 1

One request

SELECT p.* FROM Posts p INNER JOIN Subscriptions s ON s.category_id = p.category_id -- также join images img on img.post_id = p.id но тут группировать придётся WHERE s.user_id = :user_id 

Your architecture is normal, each entity has its own table.
Nothing superfluous, all links are in place.