How to build blog application using microservice architecture?

10/10/2019

I already have a blog application which is built on Spring-Boot as a monolith. There are 2 entities.

  • user
  • post

And the mapping is one to many.

A single user can create multiple blog posts.

How can i recreate the same functionality as separate microservice applications.

So far on researching through internet, what i see people saying is create database per service etc.

Suppose if i create 2 services say

  • UserService(which has separate DB and CRUD operations associated with it)
  • PostService(which has separate DB and CRUD operations associated with it)

How can i make communications in between them.

In the monolith app the POST entity has createdBy mapped to User.

But how this works in Microservices architecture?

Can any one please help me how can i design such architecture?

-- Syed
docker
java
kubernetes
mysql
spring-boot

1 Answer

10/10/2019

First list out the reasons why you want to break it in micro-services. To make it more scalable (in following scenarios for example).

  1. Post comments becomes slow, and during this period registration of new Users to remain unaffected.
  2. Very few users upload/download files, and you want general users who simply view comments and post comments to be unaffected, while upload/download files may remain slow.

Answers of the above question and analyzing,priotizing other NFR's shall help to determine how and what to break.

Additionally, Post service only needs to validate whether the user is a valid logged in user.(Correct?) User Service does not really need to communicate with post service at all. Further you might want to decouple other minor features as well. Which in turn talk to each other which can be authenticated via other means like(Certificates, etc.) as they will be internal and updating some stats(user ranking), aggregates data etc.

The system might also have a lot of smaller hidden features, which might or might not have to do anything with Post Service at all, which can be separated in terms of different micro-services(like video/file/picture/any binary content upload/download) also and prioritized based on computation power needed, hit frequency and business priority.

After breaking it in to micro-services, you need to run some stress tests (based on current load) to know which services needs replication and which not and needs a automatic load balancing. Writing stress load first before breaking can also help to understand which features need to be move out of the monolith first.

-- agsachin
Source: StackOverflow