> Den 16. maj 2016 kl. 20.48 skrev Maks Materkov <mater...@gmail.com>:
> 
> Hi everyone!
> 
> i' ve got an unusual question, that is probably not very specific to django. 
> We have a large multi-tenant django app, and we want to split all traffic 
> between two tenants (tenant 1 and tenant 2, for now). This tenant will be 
> connected to different databases. Our django app is 100% API, with token 
> authentication. Every request has auth_token parameter (as GET or POST 
> parameter). The token looks like: tenant1.xxxx, tenant-2.yyyy, tenant-3.xxx.
> 
> So, we want to route all traffic with tokens tenant1.xxx to app1 and tokens 
> tenant2.yyyy to app2. to do this, we need to setup something like "proxy 
> router" in front of out existing django app. We already using nginx, and we 
> can route to different backends only if token is GET parameter. There is no 
> way to route based on POST params, as far as I know. 
> 
> We are discussing several alternatives:
> 
> 1) Add LUA module to nginx (this module can read POST body data) and perform 
> routing here
> 2) Write another app (for example, based on Tornado or python3 asyncio) that 
> will be reading POST and GET params and route traffic to appropriate django 
> app. (or another languages? NodeJS (oh, no :) )? Go lang?)
> 
> What is the best option here for us? Or some completely different approach?

The answer to this depends in part on your performance requirements. Do you 
have *any* control of the client side? If so, you could simply send all API 
requests to tenant1.api.example.com, tenant2.api.example.com etc.

If you have no control over clients, the most simple solution would be to write 
a simple Django view that handles every request and passes it on to the correct 
backend. This keeps your code within Django. But this also requires two trips 
all the way down your stack and may not yield performance. I've had great 
success in the past with Nginx scripting, so that would be my next suggestion 
if the above are not viable. It may cost you a bit more in maintainability, 
though.

Erik

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/F3BE4330-C320-4C0F-B04D-799747F12F48%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to