Wuaner
Wuaner

Reputation: 969

Trade-offs of microservices and modularity architectural design?

Microservices and Modular Programming has proved to be a proper choice when design a software system. Benefits of it includes reusability, distributability, readability, etc.

We are a MOOC site using OSGI as modularity implementation:

Take 3 features as a example:

     course               project         Q&A(question&answer)

+---------------+    +---------------+    +---------------+
|     web       |    |     web       |    |     web       |
|               |    |               |    |               |
+---------------+    +---------------+    +---------------+
|     service   |    |     service   |    |     service   |
|               |    |               |    |               |
+---------------+    +---------------+    +---------------+
|     dao       |    |     dao       |    |     dao       |
|               |    |               |    |               |
+---------------+    +---------------+    +---------------+
|     Database  |    |     Database  |    |     Database  |
|               |    |               |    |               |
+---------------+    +---------------+    +---------------+

Requirements:

  1. Every course/project has Q&A module, user that participated-in can ask question about this course/project here.
  2. A standalone global(or common) Q&A entry, listing questions that aggregated from all courses/projects, and user can ask context-independent(aka, not related to any course/project) question here.

I do not know if this design or architecture(completely isolation from top to bottom of every feature) is good or not, but I'm facing some inconveniences indeed:

  1. modular web application

    Q&A feature is either a standalone feature and part of course/project. Currently I'm think both embed Q&A module as web component of standalone course-webapp/project-webapp, and standalone qa-webapp itself, but I have no idea what's the best way to reuse controllers to avoid duplicated code on web layer

  2. rational database Polymorphic Association problem

    A question maybe belong to course/project, or context-independent, and id of course/project came from another database, polymorphic association is inevitable. Currently I'm using a extra column post_to_type on table question to tackle with this.

  3. Let me say course/project can be private or public. questions listed under global Q&A entry only include questions that belong to public course/project, not private. But again, since each feature have its own database and direct access to database of other feature is prohibited, I do not have any idea what's the elegant and efficient way to deal with this.

Is something wrong with our modular design when using OSGI, or its just me thinking so uncomfortable with this? and what's the best practices to design a microservices / modular architecture, specifically in object-oriented language like Java?

Thanks!

Upvotes: 0

Views: 236

Answers (1)

wlabaj
wlabaj

Reputation: 468

The microservices should be built around the bounded contexts, which might align with what you call features here, but also might not ;) Finding the boundaries is a tricky and difficult task, and close to impossible to do correctly without having the full context of your system. Other people can offer tips or share insights from their own experience, but won't be able to give you the answer whether your model is correct or not. Also don't worry about "correct" too much, for sure there are a few ways you could structure your code and all of them could be useful. So focus on making the model useful and addressing any smells (e.g. code becoming hard to maintain, too chatty communication, etc.).

Sam Newman in his book advises to start with coarse-grained bounded contexts, which could be then split into smaller ones if needed in the future. He also has a very good chapter that talks about splitting monoliths into services. Even if you're working on a greenfield project, I recommend you have a look at his book, and other people's posts and talks on breaking monoliths into microservices. In my opinion this is the best way to get a feel how to go about finding those boundaries, what mistakes people make and how to get it right.

I also recommend to see "Modular monoliths" presentation by Simon Brown. Microservices are not the only option for modularization and Simon shares useful insights there.

Upvotes: 1

Related Questions