C
C#2y ago
muskagap

❔ How to properly design microservice architecture in ASP Net Core?

Hello everyone. It's going to be my first try to follow microservice architecture pattern. I have read lots of articles on the web but still have a few doubts and questions about this topic. I'm wondering how should I design the project in ASP Net Core. Especially: 1. should I create multiple services under one solution? 2. should I create a new solution for each service? 3. should I create API Gateway as an app in seperate solution or under existing solution (e.g. along with one of the services)? 4. should I always containerize microservices or not? 5. is it possible to deploy microservices apps without containerization? 6. I have one server with one database where all data is stored. I read that each service should have its own database. Can I use one database for each service (but each service will be using different tables , not share the same tables)? 7. does it make sense to create seperate service where all required data from database/s is stored (e.g. data from a few servers)? And then other services (e.g. Payments, Products, Clients etc.) would communicate with this data service to make CRUD operations? Normally, each service should have its own database but what about this approach? Thank you for your answers
14 Replies
Anton
Anton2y ago
solution is just for grouping projects. separate solution for each service is nonsense imo you might want to put it into a separate folder, but like you still may need to work on both that and one of the other services at the same time. ideally, generate your solution files for scoping purposes if you mean like a separate git repo, this depends on the scope of the system I'd say no, but if you've got a separate team working on that service then ut might be worth it the last point I think is called a broker
AtomicLiquid
AtomicLiquid2y ago
I'm gonna try to add to what Anton has already written, and my takes on it:
1. Should I create multiple services under one solution?
As Anton have already said, this really depends on the scope/size of your application/each microservice. If you have several team members working on it, you should definitely divide it into separate git repos to avoid conflicts. If you're a relatively small team, then I would create one parent solution with a child solution for each microservice.

2. Should I create a new solution for each service?
Yes, but whether or not to keep them in the same git repo depends on the size of the application/the project. Read 1.

3. Should I create API Gateway as an app in seperate solution or under existing solution (e.g. along with one of the services)?
Again, depends on the scope of your project. If you need/want services such as load balancing, networking and will potentially run the solution on several nodes (servers), then I'd use something like Kubernetes or Docker Swarm to handle the gateway to your microservices API's. If you decide to do the orchestration themselves, I would use something like KrakenD to handle the gateway stuff for you, or you can create an app yourself.

4. Should I always containerize microservices or not?
I highly suggest doing so, the issue with not containerizing them is that it requires you to handle all runtimes and stuff yourself, aka installing .NET core etc. There's also other considerations when not containerizing your apps, but for a microservice solution, I don't see a reason why you wouldn't want containers, it makes your life easier.

5. Is it possible to deploy microservices apps without containerization?
Ofcourse it is, but you need to handle alot of configuration stuff yourself, making features such as CD (Continous Deployment) much harder to implement. The reason being that you manually have to go into your server, pull the changes from your repo and redeploy.

6. I have one server with one database where all data is stored. I read that each service should have its own database. Can I use one database for each service (but each service will be using different tables , not share the same tables)?
Ofcourse you can, but the problem with such a solution is that if your one database runs into issues (crashes, gets corrupted and such), your whole application goes down, which often breaks the principles of why you want a microservice architecture in the first place. If you have a database instance per microservice, then if one of the databases dies, you still have all other microservices running, because they are not dependent on each other.

7. Does it make sense to create seperate service where all required data from database/s is stored (e.g. data from a few servers)? And then other services (e.g. Payments, Products, Clients etc.) would communicate with this data service to make CRUD operations? Normally, each service should have its own database but what about this approach?
Again, definitely a solution that could work, but then the microservices becomes dependent on each other. It's your choice and it depends on your (or your customer's) requirements for your application/architecture.
1. Should I create multiple services under one solution?
As Anton have already said, this really depends on the scope/size of your application/each microservice. If you have several team members working on it, you should definitely divide it into separate git repos to avoid conflicts. If you're a relatively small team, then I would create one parent solution with a child solution for each microservice.

2. Should I create a new solution for each service?
Yes, but whether or not to keep them in the same git repo depends on the size of the application/the project. Read 1.

3. Should I create API Gateway as an app in seperate solution or under existing solution (e.g. along with one of the services)?
Again, depends on the scope of your project. If you need/want services such as load balancing, networking and will potentially run the solution on several nodes (servers), then I'd use something like Kubernetes or Docker Swarm to handle the gateway to your microservices API's. If you decide to do the orchestration themselves, I would use something like KrakenD to handle the gateway stuff for you, or you can create an app yourself.

4. Should I always containerize microservices or not?
I highly suggest doing so, the issue with not containerizing them is that it requires you to handle all runtimes and stuff yourself, aka installing .NET core etc. There's also other considerations when not containerizing your apps, but for a microservice solution, I don't see a reason why you wouldn't want containers, it makes your life easier.

5. Is it possible to deploy microservices apps without containerization?
Ofcourse it is, but you need to handle alot of configuration stuff yourself, making features such as CD (Continous Deployment) much harder to implement. The reason being that you manually have to go into your server, pull the changes from your repo and redeploy.

6. I have one server with one database where all data is stored. I read that each service should have its own database. Can I use one database for each service (but each service will be using different tables , not share the same tables)?
Ofcourse you can, but the problem with such a solution is that if your one database runs into issues (crashes, gets corrupted and such), your whole application goes down, which often breaks the principles of why you want a microservice architecture in the first place. If you have a database instance per microservice, then if one of the databases dies, you still have all other microservices running, because they are not dependent on each other.

7. Does it make sense to create seperate service where all required data from database/s is stored (e.g. data from a few servers)? And then other services (e.g. Payments, Products, Clients etc.) would communicate with this data service to make CRUD operations? Normally, each service should have its own database but what about this approach?
Again, definitely a solution that could work, but then the microservices becomes dependent on each other. It's your choice and it depends on your (or your customer's) requirements for your application/architecture.
I'm not an expert on this, but these are my two cents after working with microservices for the last 4-5 years based on my own experiences.
muskagap
muskagapOP2y ago
@AtomicLiquid thank you a lot for your guidelines. If you have 4-5 years of experience in microservices then you must be expierienced 🙂 Getting back to 1st question and your answer - should I click on a solution > Add New Solution Folder > and add there web api which is going to be my service? I ask because you said i need to have parent solution and other child solutions containing microservices. So the project tree should look like the one I attached below? I just created 'solution folders', can't add anything else.
muskagap
muskagapOP2y ago
As for 3rd question - I need to create simple API Gateway, just a point to route requests between services. I will run all solutions on one server (most likely IIS)
Anton
Anton2y ago
child solutions? huh is that a new feature?
AtomicLiquid
AtomicLiquid2y ago
Child solutions was meant to be child projects😅 But not really sure if that would make sense either haha I'm coming from the java world, so it's somewhat different than .NET
muskagap
muskagapOP2y ago
Ok, so you mean I should create seperate services directly under solution, sth like that below? And they are new WebAPI projects at the same time
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
muskagap
muskagapOP2y ago
Ok, thank you. So if microservices ought to be used for such gigantic projects then there's no too much sense using microservices to medium size apps. I just wanted to introduce new approach of creating apps in my company. Instead of creating MVC app I decided to do it using different approach. I started creating 2 seperate apps: UI (Vue.js - frontend) and Net Core API (for the whole logic and db - backend). Then to connect them via API. I just wanted to replace Net Core API app to smaller services as to avoid the situation where one back-end app is packed with too much logic. So I made up my mind to follow microservice architecture which seems better approach. I would create a few seperate services reponsible for given business logic (Products, Payments etc.). Hope it makes sense, if no maybe there's some other solution.
Mayor McCheese
Yeah I want to say;put the compiler down and no one needs to get hurt; plan out your scheme for independence first; are you really just building a distributed monolith?
toddlahakbar
toddlahakbar2y ago
I smell destructive decomposition
muskagap
muskagapOP2y ago
I'm wondering if microservices are reasonable approach in my case. I write an app on my own, I don't have a team. My app seems to be complex in terms of funcionalities, analysis etc. But only for 20-30 users. What about approach called modular monolith? Is it possible to create a few seperate apps in such scenario (like seperate fron in Vue and seperate back in C#, where botj communitace through API?) ?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?