Member-only story

Instant realtime notifications with Symfony and Mercure

Stefan Pöltl
8 min readJul 18, 2019

--

You are searching for a handy way to build instant notifications paired with a great programming Framework? You don’t like Javascript on the serverside and difficult Websockets? You dream about a realtime application like a Bitcoin trading platform? With Symfony and Mercure you’re well prepared and I will show you how to take off.

What is Mercure?

Mercure is a notification hub where you fire HTTP POST requests to and your payload is getting delivered to all connected clients instantly. Every HTTP based Client is able to get notifications pushed in real time. But how does this work?

The mercure hub is implemented in Golang and uses Server Sent Events to transmit data to subscribed clients like this:

  • A client subscribes via HTTP to the server and the server opens a connection in read only mode for the client(unidirectional connection).
  • All the time HTTP requests are used for the persistent connection and via HTTP2 it’s possible to get multiplexing out of the box(binary framing layer in HTTP2).

The mercure server sends a message with the following headers to a client(Golang code from the mercure hub repo):

// Keep alive, useful only for HTTP 1 clients w.Header().Set("Connection"…

--

--

Stefan Pöltl
Stefan Pöltl

Responses (4)