Social Visual Page



Part 24 of Building a Social Network: Feed Broker (golang, sql)







Part 24 of building a social network for anime and manga fans. CockroachDB as the SQL database and Go as the back-end language. This is getting realtime. We use Server-Sent Events for this. WebSockets are more popular, but since we only need one way streaming… This is more ease to understand. It just keep a connection alive, and flush with each write. The concept of broker is taken from Ismael Celis https://robots.thoughtbot.com/writing-a-server-sent-events-server-in-go Please, read the post. Basically, the broker struct stores some clients and a single notifier in which you send some data. The broker fan-outs that data to all the clients. The clients are stored in a map instead of an array or slice to just use the “delete” function which is more easy I just modified it a little and added the “subscribe” function instead of using “new” and “closing” clients channels. Also, in the case of the feed broker, each client has an userID that allow us to filter to which client we’ll send data. Very important. I didn’t record this, but I improved the HTTP server with gracefully shutdown and some timeouts for best-practices, but those timeouts are grobal to the server. When using streaming, remember to not set write timeouts. Repo: https://github.com/nicolasparada/nakama #golang #sql

Leave a Reply

Your email address will not be published. Required fields are marked *