3

This might be a basic question about microservices. I searched for a few articles but not able to find anything apt. I am developing two different django rest applications (say A and B) which has to use the same authentication service. I've built the authentication service using django-rest-framework-simplejwt. My current plan is when a token is sent to A, I use TokenVerifyView from authentication service to validate the token. In certain cases where user information is required I have created a view in authentication service to return username. I'm intending to achieve this by sending a request to the authentication service for each view in A using a decorator. I understand this will be very slow and is a sub-optimal solution. What is a better way to achieve this? Thanks.

Kaushik
  • 553
  • 3
  • 11
  • 27
  • Do these three applications have different databases? Also, do you mean that `TokenVerifyView` is in the authentication app that you import into app A? – Saad Aleem Dec 18 '18 at 18:01
  • Yes all three applications have different databases. TokenVerifyView, which is provided by the jwt app, is in the authentication project. And I'm not importing the project as there all on different servers, I'm planning to call the URL of authentication project to get a JSON response in A, parse it and send responses in A. – Kaushik Dec 18 '18 at 18:05

1 Answers1

1

This seems correct for the most part but I'm not sure if you'd want to call an API of the authentication service for authorization during each API request to either A or B. For higher throughput, I think you should look at a message queue like ZeroMQ which could be an ideal solution here.

You could also use django-channels to enable communication between the web apps using web sockets here. This would be easier to implement out of the two solutions.

For a basic system, contacting the authorization service for each call to either microservice would work but eventually you'll run into scalability issues at which point you might need to come up with a way to contact the authorization service once. That, I feel, is out of the scope of this question but if you want to read more about that, you could look at this stackoverflow answer.

Saad Aleem
  • 1,709
  • 1
  • 12
  • 18