[Answered ]-API front-end architecture

2👍

You’re missing some points here. By your requirements I assume that you want to build a frontend (html + javascript) that queries a (RESTful) API, which will simply be a server that “speaks” HTTP.

So, your API querying has to do with your server, that is, with Django on Apache or with Tornado or.. Celery cannot “handle” your queries, but it can be useful for background tasks.

On the client-side, your AJAX calls shall trigger some server-side views that are mapped to some URLS. How you will define them is up to you. Have a look at some popular APIs ( twitter ) to see how they are structured.

Long-polling has to do with your “business” logic, and it defines a way on how to present data to the client, later.

Also, caching has to do with your server-side performance, and you are encouraged to use something like memcached or redis.

EDIT (for the edit): There is nothing wrong with your approach. Celery is the right tool to fetch data from an external API, then save the results to a database and of course use some caching. Then do some polling from the client to get the results. But, there exists a more optimal, non-blocking, elegant way of doing the same. You can use Tornado to fetch data from the external API, and when those data are ready, send them to the client. No Celery, no long-polling. A great code snippet here.

Leave a comment