Is it bad to use socket.io for most of the requests or should I only use it to push data to client?

Is it bad to replace AJAX routes (called with $.Ajax from jquery) such as:

  • GET /animals
  • GET /animals/[id]
  • POST /animals

With socket.io events (event binded on client and server so the client can have a response):

  • emit("animals:read")
  • emit("animals:read", {id:asdasd})
  • emit("animals:write", animalData)

or should I "only" use socket.io it to push data to client?

[EDIT] I could see one problem if I don't use socket io for my POST route. The problem is that I can't easely use the client's socket to broadcast data:

Server:

on("animals:write", function(data){ 
    saveAnimal(req.data)
    socket.broadcast(...)
    emit("animals:write", writenAnimal)  
})

VS

app.post(function(req,res){
    saveAnimal(data)
    // cant broadcast :(
    res.send(201,writenAnimal)
})

I will push data to clients in some other requests for sure, so all clients will have at least 1 socket.

If you don't want to push data to the client, I don't see why you would use socket.io instead of AJAX. I mean with AJAX you don't need to handle a session with the client and it would probably scaled better.

With socket.io, for every connected client you need some sort of object on the server paired up with that one client. It will use more memory on the server for no reason if permanent connections are unnecessary or unwanted.

Also, AJAX will be better if you want to re-use your code with other systems, it is working with a huge existing ecosystem of tools.

That being said, if you need WebSocket features like pushing the data to the client or doing some kind of broadcast, you might consider using socket.io instead of AJAX since it will be hard to achieve this with AJAX and socket.io offers those features.

IMHO socket.io should be used if you want real-time data provided for your website. Take for example Stackoverflow. It uses websocket to update in realtime your scores and update your notifications.

But if you really want to create application that is SEO-friendly ( I mean supporting http for serving your pages ) and more important if you are aware of the difficulties in managing sessions and permissions in socket.io, I think you'll prefer AJAX for your pages and socket.io for other realtime data.

I would use ajax for this, its http based data requests, nothing realtime.