harlow / go-micro-services

HTTP up front, Protobufs in the rear
MIT License
1.09k stars 165 forks source link

Question: what if you had to use a relational database #6

Closed tanis2000 closed 9 years ago

tanis2000 commented 9 years ago

I was wondering how would you structure the code if you had to work with data stored in a relational database? Would you use a single database? One database for each service? Any thoughts on that? Do you know any real world scenario and how they actually store data when using micro services?

Cheers!

harlow commented 9 years ago

@tanis2000 great question. For this example I don't think I'd structure the code any differently -- it has emerged as a best practice for each service to manage and control it's datastore (whether it be a relational or no-sql database).

Check this post out by @tsaleh on the "shared database anti-pattern": https://web.archive.org/web/20130102114251/http://thunderboltlabs.com/posts/soa-antipattern-centralized-db

Another nice post from Martin Fowler on bounded-context: http://martinfowler.com/bliki/BoundedContext.html

If you are coming at this from a refactoring standpoint where you already have a big relational database that you are looking break up then I'd recommend a quick read of this excellent post by @JackDanger https://www.quora.com/What-steps-have-software-developers-taken-at-startups-with-a-Monorail-a-large-monolithic-Ruby-on-Rails-app-to-successfully-break-it-into-services

tanis2000 commented 9 years ago

@harlow thanks for the links. They're all definitely worth reading. It all makes sense. Thanks so much both for this example project and the explanation.