Toma
Toma

Reputation: 2936

Is it a good idea to run Socket.io on a Firebase Cloud Function?

Implementing it works, but I have read that due to how Cloud Functions are designed they are not the best way to use socket.io. Why?

Upvotes: 10

Views: 8139

Answers (2)

mmm
mmm

Reputation: 1436

Cloud Functions are made for simple requests, they are not made for long-running processes. If you want to stick with serverless architecture, try Cloud Run. They released an update this year (January 2021) and the platform is now able to support WebSockets including Socket.io.

Here is the link to the Cloud Run documentation

Here is the link to the blog post (their announcement)

Upvotes: 3

Doug Stevenson
Doug Stevenson

Reputation: 317497

Actually, socket.io does not work with Cloud Functions. Cloud Functions have the following properties that make them incompatible with long-lived socket connections:

  1. The maximum duration of a Cloud Function can only be 9 minutes. The socket will be forced closed after that time. This is counter to the normal expectation of socket.io to keep a socket connection alive indefinitely.
  2. Cloud Functions will read the entire contents of the request, and only then will write the entire contents of the response. There is only one full round trip - a client can not "chat back and forth" over the connection with the function.

See also

Upvotes: 21

Related Questions