Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Is sending HTTP POSTs to Django Web API via node.js efficient?

Is sending HTTP POSTs to Django Web API via node.js efficient?

Problem

I've built a JSON API in Django. I'd like to send real-time updates from an external service to Django to upsert a model.

I am really looking for insight on the best way to design the system with current/upcoming/active frameworks and tools. My thoughts are using node.js/Django/Foreman described below:

  1. Existing Django JSON API
  2. A node.js app, running via Foreman, that's subscribed to some external channel.
  3. That channel sends node a JSON message
  4. Node consumes message and makes an HTTP POST of JSON to a URL within my Django API.
  5. Django API uses the JSON message to upsert a model within the Django application.

Now, it seems that I should be able to eliminate node.js from this equation, and have a service that lives "a little closer to home", home being the Django app, rather than having to cross HTTP.

Question being: Is the solution I have now an efficient approach, and is there a better way of doing things?

Problem courtesy of: kturner

Solution

How do you need to subscribe to the other service? If the other service calls one of your Urls directly, just make Django listen there.

If the other service requires your side to act as server (non webserver, eg connects to you on some non web port) you will need to let a server run there, but again I wouldn't use Node but rather write a simple Python server (probably using the asynccore module), which you could start via foreman+manage.py and which would have access to models directly, eg wouldn't need to marshal the data into json just to send it to Django.

If you connect to the other service via a simple tcp connection I still would take the non node approach like described above.

P.S.: Don't bother to much about efficiency -- keep your system as simple as possible before developing over engineered solutions.

Solution courtesy of: Florian Apolloner

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Is sending HTTP POSTs to Django Web API via node.js efficient?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×