Building real-time systems on top of Drupal with Node.js

Click to watch "Building real-time systems on top of Drupal with Node.js"

The creator of the Drupal package for Node.js goes over how to leverage the strengths of Node.js to compensate for some of the Drupal stack’s weaknesses, especially when creating real-time system with chat and queue systems as examples.

Speaker(s): 
Track: 
Coding and Development
Experience level: 
Advanced
Time slot: 
Thursday 14:15-15:15
Room: 
Atlanta

Comments

I looked at the project you linked. Is it best practice to interact directly with the database instead of using Drupal's APIs?

…but that's probably a bit simplistic.

The issue we were trying to address with this project is actually very much related to this question. In our experience, Drupal’s API (being PHP, and thus shared-nothing) is simply too slow/heavy for the needs of real-time systems. Even if your app’s usability doesn't suffer from ~600 ms roundtrips to the server for every action performed, your database server will soon reach its limits from doing dozens of Drupal bootstraps every second.

Just loading all your stored settings, initialising modules, and all the other steps required for bootstrapping Drupal, so you can use it's API can easily result in dozens of database queries. Before migrating to Node.js, one of our client sites were making around 1.500 database queries a second just from 30-40 users online on a fairly simple app.

My Drupal module for Node.js aims to reimplement a few select features of Drupal’s API, so some of the most critical things for real-time interaction are possible in a scalable fashion.

Do you think it would be possible to alter your Drupal module for Node.js to work with Mongodb (as used with http://drupal.org/project/mongodb)?

I have been looking into support for multiple backends (Redis, PostgreSQL, Memcache, etc.), and I will likely have to do at least PostgreSQL for an upcoming project. I probably won't do MongoDB myself, as I have no need for it, nor any real-world use case to test it on, but I’ll happily try to assist anyone who’d like to implement it.

What are you guys using for syncing authentication from node.js with Drupal?

I will cover this in more detail in my presentation, but basically, Node.js receives the session cookie ID and queries Drupal’s session table to figure out who the matching user is. When that is determined, Drupal's roles/permission tables can also be queried within Node.js to figure out if a certain user has a Drupal permission.

Barring bugs in my implementation, this is just as secure as Drupal's own user/access system.

Thanks for the response. Do you know if you're presentation will be recorded? I unfortunately won't be able to attend.

All official sessions at all the recent DrupalCons have been recorded, so I’m pretty sure this one will also be – likely just screen output + speech, so you won’t be able to enjoy me handwaving at the screen :)

Thanks for posting the nodepal demo. The approach you've taken is interesting and seems to be a good fit for what I'm working on. I had trouble implementing nodepal with my install of node. I received errors about a deprecated connect function, and my attempts to work around that haven't been the most successful. However, I was able to use portions of your code in my own project, sending a session ID through to see if the user is logged in and returning some basic user data.

I like the approach of using the session ID but I'm a bit unclear on where the sid should come from. In your example, the sid is hard-coded into the settings file. Would this be read from the standard Drupal cookie and, if so, how would you determine the cryptic name of the cookie? Would you log a user in via ajax to a custom Drupal function, return the sid and store it separately instead?

Your thoughts on this would be greatly appreciated.

Sorry, I realize now that synodinos was the author, not yourself. However, the concepts that you're talking about seem to be the same and I'd still be interested in hearing your thoughts.

Can you list some of the stack weaknesses that you will discuss during the presentation?

Not quite sure what you mean by that, but I will go into some of the main challenges of developing real-time system and the impedence mismatch between Drupal’s simple, stateless approach, and the great challenge that is syncing state between client and server :)

Was looking for article. It had been useful understanding. Will continue a look at for your blog regarding most recent changes. Regards.property for rent Spain

This link does not work?