Django + microservices: What's correct approach?

已查看 6,107 次
跳至第一个未读帖子

cr0hn

未读,
2015年8月24日 03:18:362015/8/24
收件人 Django users
Hi guys,

I'm investigating about how to use Django as a microservices architecture, but I'm so surprised that I don't found almost information about that.

Could you help me with some resource, documentation and anything?

Thanks!

Cheers

François Schiettecatte

未读,
2015年8月24日 07:50:412015/8/24
收件人 django...@googlegroups.com
What do you mean by microservices? What are you looking to accomplish.

François
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dd1cbb4d-65ea-4111-9a67-1130433dfdec%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Tom Christie

未读,
2015年8月24日 11:59:012015/8/24
收件人 Django users
Django REST framework is a general purpose API toolkit, and more than capable of building microservice-type services. Likewise there are plenty of frameworks in alternative languages that are also suitable for building APIs that could be characterized as 'microservice'.

The reason you're finding it hard to discover much on the subject is probably due to microservices being an architectural style, rather than a framework choice.

Are there any *specific* technical issues that you're looking for help with? What sort of service are you building, and is this for a Web App frontend, a native client, both or something else?

Aside: Unless you've got automated deployments nailed, great monitoring, a heavily used service with a really nicely designed separation of concerns, and a culture of personal responsibility for the engineers taking code-to-deployment then the microservices probably (as a super-rough rule of thumb) isn't worth the extra up-front infrastructure it requires.

cr0hn

未读,
2015年8月25日 03:42:062015/8/25
收件人 Django users
Thank you for your responses.

I try to find some guide to create micro-services architecture using Django. I know that micro-service is a design paradigm, so I'm looking for the best way to implement it using Django (+ django-rest-framework).

I also know that there're not a unique response, but I would like to answer questions like that:
Create a Django project for each micro-service or all using the same project?
  • Micro-services must communicate themselves using the same REST API, some way for better approach?
  • How to deploy the project: Running "python manage.py runserver" or something like "python manage.py start MY_MICROSERVICE"?
  • How to communicate the services for reduce response time and using async way?
I know how to implement all of things above, but I'm looking for some recommendation of someone who have had the same problem or who has created micro-services with django.

I hope I explained better now :)

Regards.

Steve McConville

未读,
2015年8月25日 06:34:472015/8/25
收件人 django...@googlegroups.com
Hi Crohn.

You're asking a lot of related but very general questions here. I know
you are looking for someone who has "had the same problem" but we
don't know what your problem is. The whole point of any architecture
is that it's supposed to be a solution to your problems, not a problem
in itself :) If you tell us what you are trying to create (roughly
from the perspective of your users) and why you want to solve that
problem with microservices and Django, there may be sensible advice
people on the list can offer. Anyone who offers you architectural
advice before knowing what your system actually does is usually
selling something.

Many of the resources you'll need to learn about architecture and
about Django implementations will have been published before 2014, and
hence won't contain the word "microservices".

To address specific things you've asked (none of which are specific to
microservice architectures):

1. REST
Django is a HTTP application framework, and you can obviously use any
approach that HTTP supports, including REST. RESTful or RPC-like
services using JSON as a serialisation format are common.
Django-rest-framework is obviously geared towards REST :)

2. Deployment
The built-in runserver is only appropriate for development, and
certainly not for a services based approach. The normal way to deploy
django applications is with a WSGI server such as uwsgi or gunicorn.
These are typically run behind a reverse proxy or load balancer. If
you are planning to deploy many services, it's worth automating this
process as much as possible. There's good recommendations on how to
deploy Django for production in the docs:
https://docs.djangoproject.com/en/1.8/howto/deployment/

3. Performance analysis
Performance analysis of communicating services can be tricky. To
master it you'll need a grasp of distributed systems and queuing
theory and this will take a lot of reading, maths and experimentation.
There are books and software that can help you with this such as PPA:
http://www.perfdynamics.com/iBook/ppa.html

4. Async
Django is not designed to be an asynchronous server. Async webapps are
usually more complex than synchronous ones. You may be better off
either:
a) using one of the queueing systems for Django
https://www.djangopackages.com/grids/g/workers-queues-tasks/
b) using things like asyncio, gevent or twisted if you are *sure*
you need them.

I hope this is a helpful response, and good luck with your project!
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ceefe6b9-ab71-405c-abae-dc09ed3f695f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
steve
http://stevemcconville.com/

Tom Christie

未读,
2015年8月25日 07:02:112015/8/25
收件人 Django users
> Create a Django project for each micro-service or all using the same project?

Different projects.

Micro-services must communicate themselves using the same REST API, some way for better approach?

The API *is* the service boundary yup.

How to deploy the project: Running "python manage.py runserver" or something like "python manage.py start MY_MICROSERVICE"?

Same way you'd deploy any other Django service.

>  How to communicate the services for reduce response time and using async way?

Just use requests, and don't worry about this.

But finally and most importantly:

Almost certainly *don't bother*. Micro-services have a large up-front cost, and they're not worth it unless you've got a good reason to do so (eg you have a large service and you know that you need to scale different components independently, and ensure distributed reponsibilities across a large engineering team)

Unless you know that you've got an issue like that and you can pinpoint it, it's unclear why a microservices approach would be preferable. (If you're purely looking at this as a learning exercise then that's slightly different)   

A single project providing an API for your front end is *far* more likely to be what you're actually looking for.
回复全部
回复作者
转发
0 个新帖子