Activity feed on any socialising platform shows the updates/news and as it says, activities of your friends and people whose activities you are authorised to view. Anything – a news feed, chat message, connection request or a notification is an activity feed.
Let’s take a brief overview how we can implement activity feeds in our socialising mobile/web applications taking an example of how we achieved the same.
Every activity feed has following properties:
- Creator – user who initiates/creates the activity.
- Info – content of that activity.
- Audience – set of people who are going to see that feed in real time.
- TrackableType – tells the type of activity (in particular model of the activity).
- News Feed
- Friend Requests
- Chat Messages
Whenever a user creates any activity, a process attached to it is queued in Sidekiq. Sidekiq is a full-featured background processing framework for Ruby. For more info on sidekiq – https://github.com/mperham/sidekiq/wiki.
Before creating/updating any activity its audience is saved/updated first. So that we will:
- add feed to new audience,
- update feed to old audience (if feed is being updated),
- delete feed from removed audience
To store user data in user’s bin redis caching is utilized. Sidekiq uses Redis to store all of its job and operational data. For more info on using redis – https://github.com/mperham/sidekiq/wiki/Using-Redis.
After activity has been published/unpublished to/from user bins at the backend, it also needs to be updated on user side in real time. To achieve real time updates on user side faye server is being used. Faye is a publish-subscribe messaging system. It provides message servers for Node.js and Ruby, and clients for use on the server and in all major web browsers. For more info on faye – https://faye.jcoglan.com/.