Home >Backend Development >Golang >How to associate a multi-subdomain website with a separate database?

How to associate a multi-subdomain website with a separate database?

WBOY
WBOYforward
2024-02-05 22:18:08456browse

How to associate a multi-subdomain website with a separate database?

Question content

I use sso to develop a multi-subdomain website with independent databases, as shown below:

  • www.example.com (company website and store) - www_db

  • blog.example.com - blog_db

  • forum.example.com - forum_db

  • account.example.com - login, registration, account_db (user)

I have a problem, on the forum, the user must be able to add posts, then when rendering the post list, I have to get the user data for each post: username, avatar, etc., but since the user and the post are in different In the database, how do I do that?

I don't understand how it is posted, I think getting the user by user_ids from the post via API but too many requests


Correct answer


Okay , let’s proceed one by one:

I'm assuming this is a question about authentication, in which case you can make a request to the AccountService via the MessageQueue to get permissions for that specific user. This can be a heavy burden on the network if you have a lot of traffic - but this can be optimized by caching each user and their permissions in ForumService.

Additionally, you can implement a gateway API that performs the initial acquisition of the user on the first request and then further propagates the user data to the underlying service.

The same situation as auth also applies. You can get these users one by one and cache them for as long as you deem necessary. Of course, you will temporarily lose some data consistency, but you will gain availability and reduce network traffic (eventual consistency). You can also make the AuthService emit a UserChangedNotification and reduce inconsistencies to an absolute minimum.

https://obeycode.com/articles/7 /Microservice simple terminology---Introduction

The above is the detailed content of How to associate a multi-subdomain website with a separate database?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete