Fanout on write approach to build a timeline with SQL and Golang

Nicolás Parada
1 min readJul 24, 2022

--

A screenshot of a post fanout SQL query

I've been recording the process of building a social network with Go. And on the last video I covered how to do a fanout on write of the posts to build the home timeline (also known as activity feed).

Video here: https://youtu.be/swuoPEPElDw

The fanout on write technique trades a slow write, to have a faster read later on.

Instead of doing query to fetch all the posts where the post belongs to a follower, we just fetch the posts directly from the timeline table so we avoid doing an expensive join with the followers table.

Using SQL, the multi write (fanout) is quite easy to do using an INSERT INTO … SELECT …. We don't need any other processing system; just pure SQL.

Checkout the video and leave any question in the comments, or here, or you can even join the slack channel here. I can detail more about the fanout on write approach ;)

See ya.

--

--

Nicolás Parada
Nicolás Parada

Written by Nicolás Parada

Cloud Backend Engineer that loves Golang

No responses yet