I’m looking for some best practises help… I have m...
# sst
j
I’m looking for some best practises help… I have multiple stacks and I’m treating each as its own microservice so I have stacks for
CustomerProfile
,
Order
,
Fulfilment
etc. For data storage I’m planning on using Postgres and I want each stack to have its own database, rather than having one database that everything accesses. I could create an RDS Cluster in each of the stacks, but I don’t think I want multiple clusters, just multiple databases. Is there any opinions on this and how would migrations work… for example each database could have its own view of what a Customer is… so I’ll have several
Customer
entities not a single one.
j
Hey, it would be worth taking a look at some best practices around micro services in general but here is my 2 cents. You want one Stack (probably CustomerProfile) to own the Customer object. So only that stack stores the customer information in their DB. Then all other stacks (e.g. orders) will store the ID for a customer against the orders, only the CustomerProfile has the Customer info actually stored. You’ll then need to build some kind of API or other mechanism for the Order service to access this customer info when needed. Wherever possible you want to be clear about what each micro service is responsible for, make sure it owns its own data, and talks to other services to get data it doesn’t own instead of duplicating it. Good luck!
j
Hey James, thanks for the reply… I realise I should have probably put more details in the post! So I’m wanting to avoid lambda -> lambda invocations and the environment is an event driven model so any changes to customer (not the same as user btw) will be on an event which the other services will consume and pick off the fields that they care about… so for example the fulfilment service will keep the customer name updated from the events but will not store 80% of the rest of the data. This will keep the ownership of the data, as the only thing that emits events for an entity will be the services that owns it… but it also allows each of the services to operate independently. My question is more around the RDS Clusters and how you can operate a single cluster with multiple DBs (and how the migrations will work for that) and if this is a decent approach vs each stack having its own cluster.
f
Lemme double check with Dax. @thdxr is there a way to run migrations on non-default database? And do we support quering non-default database in SST Console?
t
in the console yes, you can switch to a different DB and run migrations/query it
Copy code
database: evt?.database || process.env.RDS_DATABASE,
when invoking the migration lambda you can pass in evt.database which the frontend does - I'm not sure if there's a way to do this through our construct though