I development multi subdomain website with separated databases with sso, like as:
www.example.com (corporate web & shop) - www_db
blog.example.com - blog_db
forum.example.com - forum_db
account.example.com - login, register, account_db (users)
and I have one problem, on the forum, users must can to add posts, and then when render posts list, I have to take user data with each post: username, avatar, etc., but since users and posts are in different databases, how can I do this?
I can't understand how it's release, I think getting users by user_ids from posts via API, but it's too many requests
Okay, let's do this one by one:
On the forum, users can add posts
I'm assuming this is a question about Auth, in which case you can make a request via MessageQueue
to the AccountService
for permissions of this specific user. This can be heavy on networking if you have a lot of traffic - but this can be optimized by caching every user and his permissions in ForumService
.
Additionally, you could implement a Gateway API that performs initial fetching of users upon first requqest and then propagades user data further into underlying services.
When you fetch and render a list of posts, user data is needed, such as: username, avatar, etc., but users are located in different services - so, how can I access them?
Same thing applies as with the auth. You can fetch these users one by one and cache them for however long you deem necessary. Sure, you'll temporarily lose some data consistency, but you'll achieve availability and lower network traffic (Eventual Consistency). You can also make AuthService
emit UserChangedNotification
and reduce inconsistencies to absolute minimum.
https://obeycode.com/articles/7/microservices-in-simple-terms---introduction