I am using Ruby on Rails 3 and I would like to handle user authentications in a Service-Oriented Architecture (SOA).
At this time I have 3 applications located (for now) on the same server:
- pjtname.com
- users.pjtname.com
- others.pjtname.com
I would like to use memcached (it is a very awesome way to avoid to query the database), but I’ve heard of problems that can happen when the system goes out of memory, such as the problem for users not being able to log.
However, I am thinking to store in the pjtname.com cache at least the user_id values so that is more hard to go out of memory. The following are steps at what I am thinking to do, but I don’t know if it is the best way to accomplish what I aim.
- send user credentials from
pjtname.comtousers.pjtname.comover SSL; - on the
users.pjtname.comside use a middleware to intercept and sign in the user; - on sign in success, send back the user session authentication information (example: the
user_idstring) fromusers.pjtname.comtopjtname.comover SSL; - on the
pjtname.comside look foruser_idin cache and if that is expired start again at the step 1.
So, do you advice to use memcached for that purpose?
- If so, where I can start?
- If no, what approach is recommended?
UPDATE for @Mörre comment
Why do you want to send authentication
info between the sites, can’t they
just get the session data from the
(same) database?
It is because I am trying to scale RoR applications on different servers each of them with its own database.
To give architecture advice one would
have to see the WHOLE picture, what
your task is from the customers point
of view, and know their intentions and
constraints.
The “picture” is that I have 3 RoR applications (pjtname.com, users.pjtname.com and others.pjtname.com) for which I need to handle data in order to improve the whole system performance. In this case I need to handle user session on a central place (pjtname.com) in order to access to the other application datas (users.pjtname.com and others.pjtname.com) only if the current user is authenticated, that is, signed in.
Given what you’ve explained so far, my answer would be no, I would not recommend this. Use a before_filter to authenticate, store the auth in the session.
Now if you had asked if you can use memcached as a session store, I’d say that it is possible. But the overly-complex message-passing scenario you’ve described would not be helped by using memcached.