For AI agents: this page in Markdown: https://www.pubnub.com/docs/faq/architecture.md. Documentation index: https://www.pubnub.com/llms-full.txt.

Architecture FAQ

10 questions on this page

Short answers to common questions about PubNub architecture.

Does PubNub use a lot of battery power?​

No. Each client instance typically holds at least two connections. One is dedicated to the subscribe long-poll, and one or more handle all other operations. The exact count depends on the SDK, request concurrency, and HTTP version. A client subscribes to all its channels over that one subscribe connection, so its battery cost doesn't grow with the number of channels. A subscribe request is held open for up to 310 seconds before the client reissues it with an updated timetoken cursor.

To save more battery on mobile devices:

Why do I see multiple GET requests in the browser console?​

The repeated GET requests are PubNub subscribe calls. PubNub doesn't use WebSocket. The SDK uses HTTP long polling instead. Each subscribe request stays open until a message arrives on a subscribed channel. A subscribe request is held open for up to 310 seconds before the client reissues it with an updated timetoken cursor.

Other GET requests come from publishes, presence heartbeats, history, and other API calls. See Data transport and delivery.

How do I check network connectivity?​

To check that your network reaches PubNub, call the PubNub Time API from inside your network with curl, wget, or a browser:

curl https://ps.pndsn.com/time/0

A response with a timetoken means the connection works.

To detect dropped connections in your app, add a status listener before you subscribe. The SDK reports connection changes to it. See Monitor and respond to connection status changes.

What is an HTTP 499 status code?​

Status 499 means the client closed the connection before PubNub returned a response. It's a normal part of web traffic, not an error.

In PubNub, the main cause is a change to the subscribed channels. Adding or removing a channel cancels the open subscribe request and starts a new one with the new channel list. Requests are also cancelled when the client timeout runs out or when a user closes the browser tab or refreshes the page.

A sudden rise in 499 responses can point to a problem. Check whether you set PubNub timeouts lower than the defaults, and whether your clients' networks are unstable. See Client closed connections (499).

Which SDKs support HTTP proxies?​

All PubNub SDKs work through transparent proxies, which don't change requests and responses. An SDK supports proxy configuration if its configuration reference lists proxy settings, for example Java, C#, Kotlin, and Go. The JavaScript SDK supports a proxy in Node.js with setProxy(). In the browser, it uses the browser's proxy settings.

Why do I get a 403 Forbidden error?​

Usually because of Access Manager, which controls who can read and write each channel. PubNub returns 403 when:

To see what a token grants, see Check permissions. For all error responses, see Error codes.

Why do I get "[XYZ] is not enabled for this subscribe key"?​

The API you called needs a feature that's turned off on your keyset. For example, history needs Message Persistence, channel groups need Stream Controller, and Here Now needs Presence. Turn on the feature named in the error. See Enable the features your app calls.

Is a connection closed when I shut down the PubNub object?​

No, not by itself. Most SDKs release their connections, timers, and threads only when you tear the client down explicitly, for example with destroy(). A client you abandon keeps its sockets open until then.

In the browser, the browser may also keep the connection open for a while after it becomes inactive. See Connection management.

Should I use the restore setting?​

In the JavaScript SDK, restore is true by default, so you don't need to set it. It works only in the browser and needs listenToBrowserNetworkEvents set to true.

When the network goes down:

  • true keeps the current timetoken and channel list, so the client catches up on missed messages when the network comes back.
  • false tears the client down on network loss, and you subscribe again yourself when the network returns.

See Detect a browser network drop sooner and JavaScript configuration.

Can one account support several environments?​

Yes. Create a keyset for each environment, for example one Testing keyset per environment and Production keysets for live traffic. A Free account can have up to 10 active keysets. Disabled keysets do not count toward the limit. Creating a Production keyset requires at least the Starter plan. Testing keysets are rate-limited and aren't suitable for live traffic.

See Create a keyset and Keysets.

Was this page useful?

Last updated on