DEV Community

Cover image for Deploy a free, open-source Pusher alternative πŸ“‘
Alex Renoki
Alex Renoki

Posted on

Deploy a free, open-source Pusher alternative πŸ“‘

I’ve been many times in a situation where I needed Pusher to broadcast messages from Laravel events to the frontend applications. This can be a bummer when you don’t have enough money to pay for a Pusher plan once you reach a specific threshold or you want to manage the Pusher instance yourself and scale it yourself, as an alternative.

pWS is a free, open-source alternative for the Pusher service. πŸ“‘

The server is built on top of uWebSockets.js β€” a C application ported to Node.js, that claims to be running 8.5x that of Fastify and at least 10x that of Socket.IO. (source)

The difference between pWS and Socket.IO is in terms of speed. pWS is supported by Pusher-maintained clients, bringing portability and plug-and-play functionality with already frontend apps that already use Pusher clients.
The server is entirely compatible with the Pusher Protocol v7 and tries to keep up with the HTTP REST API reference as fast as possible.

Contrary to Pusher, you do not need Pusher credentials or a Pusher plan to make it work. The application is a standalone, plug-and-play alternative to Pusher.

πŸš€ Installation

pWS is available as CLI or as a Docker container, bringing full flexibility to run in the environment you wish.

npm install -g @soketi/pws
Enter fullscreen mode Exit fullscreen mode
yarn global add @soketi/pws
Enter fullscreen mode Exit fullscreen mode

To start the sample server, run:

pws-server start
Enter fullscreen mode Exit fullscreen mode

When running with Docker, all you have to do is to find the right image you want to install:

docker run -p 6001:6001 soketi/pws:1.0.0-14-alpine
Enter fullscreen mode Exit fullscreen mode

After this, a Pusher server is available at port 6001:
Pusher clients are fully compatible with the WebSocket protocol implemented in this project. You just have to point the client to the server address:

const PusherJS = require('pusher-js');

let client = new PusherJS('app-key', {
    wsHost: '',
    wsPort: 6001,
    forceTLS: false,
    encrypted: true,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],

client.subscribe('chat-room').bind('message', (message) => {
    alert(`${message.sender} says: ${message.content}`);
Enter fullscreen mode Exit fullscreen mode

πŸ‘¨β€πŸ”¬ App Management

Apps can be defined at the configuration level or can be pulled from a third-party API, such as MySQL or PostgreSQL for better management of who can access the WebSockets server and who can publish the events.

pWS has support for SQL-based databases and even DynamoDB and can be easily configured via environment variables.

↔ Horizontal Scaling

pWS is optimized to work in multi-node or multi-process environments, like Kubernetes or PM2, where horizontal scalability is one of the main core features that can be built upon. The main concern when scaling horizontally is how can I make the nodes communicate between them?
To be able to scale it horizontally and efficiently enable node-to-node or process-to-process communication, pWS leverages a Redis connection.
You can configure pWS to run with Redis as a primary adapter for the local-persistent data with an environment variable:

ADAPTER_DRIVER=redis pws-server start
Enter fullscreen mode Exit fullscreen mode

πŸ“ƒ Extensive documentation

pWS has many other supported features, like rate limiting, graceful shutdowns for servers that still have active connections, Prometheus support for scaling, and even compatibility for Pusher Webhooks to send frontend events to your backend.

Read the extensive documentation on

πŸ™Œ Contributing

Please open issues or feature requests within the Issues board on Github or if you think there are some improvements needed, submit a Pull Request and we will discuss it there.

πŸŽ‰ Supporting our work

If you enjoyed this article or you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, spread some kind words about our work or sponsor our work via Patreon for some exclusive articles full of Laravel tips and best practices. πŸ“¦

Discussion (0)