Data and Microservices

Data and Microservices

When you first meet the concept of microservices, you find it striking how simple the ideas are. They are also not new. SOA applied at a more fine granularity of service. So? What's new? 

You can get hundreds, and probably, thousands of answers. And they are mostly simple and logical. The most salient one being independent deployablitly, and the "micro" characteristic.i.e, the smallest deployable component. It remains up to you to define what "smallest" means for you. There are many details of design, testability, composability, manageabilty, fit with your agile cycle, etc. There are many best practices readily available online. Nothing new in any of these ares. Most of these problems have existed for a long time and they have solutions and best practices.

The one aspect that I have found the most difficult to wrap my mind around, is the stipulation that there is to be no shared access to data between services and no direct access to data outside of services. That is such a simple and elegant goal - but sounds impossible to implement. After all, that is the very definition of a database - take data ownership away from applications and put it in a "shared" database. It took database technology thirty years to reach a point where this is universally acceptable, and desirable. That is the crux of database thinking, and database design. To remind yourself of how established and accepted this notion is (shared data) browse through a good text on database design.

So, not to make this post too long, I highly recommend googling on "data and microservices", if you want a quick understanding of how to solve this simple, yet difficult, problem.

There seems to be almost universal agreement on a few architectural and implementation concepts. I will just mention them here, and we can later investigate them in more depth. In the meantime check with uncle Google.

The few architectural principles  are:

  • Bounded Contexts (from Eric Evans' DDD Domain Driven Design)
  • Aggregates (also from DDD)
  • CQRS (Command/Query Responsibility Separation). or CQS - Command/Query Separation - inspired by DBC (Design By Contract) at the object level. CQS is the DBC variant for services. DBC helps with clean object design. CQS helps with clean service design. Very beneficial to be familiar with both.
  • Event Sourcing - Extremely important if you want to separate data ownership by service. An updating service needs to notify query services of what it has done. Eric Evans introduced Domain Events, after the book was published, and he and the DDD community have written and presented on the concepts extensively.
  • Independent Deployment. Technologies like Docker. 

I think if you have a solid understanding of how to implement "no data sharing among microservices", the rest of it are implementation mechanics.

I'd rather disagree with the main provision made in this post, that services should have "no shared access to data", and it needs to be somehow enforced programmatically. Quite an opposite, microservices deployed in containers (like Docker platform) -should have transparent access to Db. Crux of the matter, that Database itself via data access requests insulation and/or serialization shall RESTRICT concurrent access to data. And here a lot depends on particular design of microservices (simply put - whether you going to lock access at table level, or at individual record level). And BTW containers + microservices concept evolved from deployment of multiple instances of the same web app across set of virtual servers with a load balancer ahead. Most likely it would be two major roads of future development - Hybrid cloud (Db) + containers + microservices for in-house applications and AWS with serverless microservices for "public" (low security) applications

Like
Reply

To view or add a comment, sign in

More articles by Nabil Hijazi

  • Strunk and White Applied to AI Writing

    You want AI-generated text that sounds human. Not robotic.

  • Groovy Fun with Git - Part 3 of 3

    Design and Coding of the Groovy Script When I started considering Groovy as an alternative for Bash scripting my goals…

  • Groovy Fun with Git - Part 2 of 3 - Using the Groovy Script

    In Part 1, I introduced a simple script to help explore the Git data structures, as we do simple experiments with git…

  • Groovy Fun with Git - Part 1 of 3

    Pro Git, Scott Chacon's great book on Git, has a chapter on Git internals that is a must read, if you want to take a…

  • Microservices and Database Replication

    In a previous post, I discussed briefly the issue of data sharing in microservices. The consensus seems to be that each…

    2 Comments
  • Microservices - It's Not The Size That Matters!

    The diagram above is NOT something you want! That is how to do microservices the wrong way. In many ways "micro" is not…

    9 Comments
  • Why Microservices Are Hard

    Microservices are the latest incarnation of a "software brick" - an independent software component. A software…

  • Database Considered Harmful?

    Think "Events" (not CRUD) As you dip your toes into the world of microservices, you start thinking this is great stuff,…

  • Decomposing into Microservices

    Event Partitioning: Old Idea from Structured Analysis. A Perfect Fit for Microservices Thinking.

  • Dependency Hell in Microservices and How to Avoid It

    In my previous post I talked about independence being THE defining characteristic for a microservice. It is also the…

    1 Comment

Others also viewed

Explore content categories