4
eval
6y

Does anyone know why websockets aren't used far and wide for APIs? I mean not like chat applications, but the typical webapp, say an online shop. For me it seems kinda wasteful to fire separate requests with tiny payloads all the time. I currently use moleculer and socketio for a quite big project with multiple websites and backend containers, and so far, i haven't found a disadvantage.
So what have i missed?

Comments
  • 2
    I've never considered sockets for that kind of thing.

    I find sockets a pain in the ass on the best of days and that's for small scale projects, let alone going all in for an e-commerce system and APIs.
  • 1
    @norman70688 what cost would that be?

    OP's question is a good one. I was also wondering about the same thing
  • 6
    Pointless drain on server resources to keep a managed connection open if you don't require real-time two-way data flow.

    Standard HTTP makes more sense for one-way transactional communication.
  • 0
    ^^^^ What he said.
  • 0
    @kwilliams which resources in particular?
  • 2
    I'm sticking to ajax based on this

    https://cubrid.org/blog/...
  • 0
    Why not both. In our new project we use an SPA that gets its data from a standard REST-API, but also connects to a websocket. The websocket-connection is for telling the client that a specific resource has been updated, so that the SPA can decide if it has to update the cached data or not.
    This way we get a rid of polling and we minimize data-transfers.
  • 1
    @netikras since socket connections are persistent there is a maximum number a server can handle at once.
    On some servers they also consume from the HTTP connection pool .
  • 0
    @kwilliams limited to what, 65k? It seems quite unrealistic to reach this limit for the mentioned purpose, doesn't it?

    Ulimit limitations can be easily lifted - this step must always be planned as a part of infra architecture anyway

    How are websockets different from a longpoll [considering socket exhausion]?

    Afaik push notiffs use this very model - longpoll. Meaning server has thousands of sockets opened by a client, which are doing nothin but sitting in some collection and waiting to be used. The only overhead I might see is keepalive bombing, but even there I don't see much of a waste.

    MQs, which is a pure serverside-ware, also uses longpoll for subscriptions/queue drains. Haven't seen any problems there as well. Did I miss smth?

    Cloud doesn't even charge for this -nofiles resource last I've checked

    Please correct me if I'm wrong
  • 1
    @kwilliams sh!t. I should learn to read better 😁

    yupp, you're right. Idk why nor how, but I thought that OP is asking about comms between microservices through their APIs

    I need a good night sleep :(
  • 0
    @TobiSGD Websocket or webhook? And just curious but why not use web hooks instead so when there’s and update you just send the notification to the client that’s waiting rather than having an open connection all the time? Unless updates are super frequent
  • 0
    @badcopnodonuts Websockets. The clients accessing the REST-API can in our case be a web app, a mobile app or, in future, backends of other modules of the project. Webhooks aren't of much use with mobile apps or web apps.
Add Comment