How to break a django website into microservices

Viewed 4309

So, I am new to this "monolith vs microservices" architecture debate and I have pretty much understood most of it. From my limited understanding I get it that in microservice architecture each feature(lets say) is a separate app. Now I need some clarification with respect to django for implementing microservices. Heres my question

Should I make every microservice aka the app a different django project altogether OR should I make every app aka the microservice inside one django project and keep them isolated (as in loosely coupled) ?

4 Answers

Microservice architecture simply states that your each service should be independent of each other.

Its also not necessary to create one micro-service in java and one in python since they are not related.

So yes, ideally your each micro-service is a separate django project. The best way to break this, first list down all the possible modules in your site or app.

Then go through : https://microservices.io/patterns/decomposition/decompose-by-business-capability.html https://microservices.io/patterns/decomposition/decompose-by-subdomain.html

These are two recommended pattern of how you should divide modules / domain into micro-services.

well, you can use database routers in django ... that does the trick ... one wSGI file per app communicating with your NGINX server

The main purpose of micro service is to serve the specific business, for example you are running a cloud kitchen then Django project can have many sub projects under one master project or you can run each project as separate service, it up to you.

Service

  1. backoffice
  2. finance
  3. rider
  4. kitchen

now we will set the url for each service like

Endpoints

  1. backoffice.mycompany.com
  2. finance.mycompany.com
  3. rider.mycompany.com
  4. kitchen.mycompany.com

Once our app is up the service load will not effect other service.

The microservice should be completely independent so it should not belong to one Django project. You should be able to deploy each service independently with its own database, so even you split the project into separate apps they still share one physical database and you can not deploy them separately. Therefore, you could potentially create separate Django project for each 'microservice' but this does not make much sense. You put lot of overhead for creating a microservice and also using Django framework is not a best choice for MSA , have a look at Flask.

Related