Hacker News new | ask | show | jobs
by gigatexal 2351 days ago
Another approach could be to create the materialized view and then use some sort of event system say the pg_notify subsystem to capture an event and then increment some aggregation -- this would eliminate the need for scheduled view refreshes and keep the view almost real-time and quick.
3 comments

This might be best done using triggers. I've had good experiences with the Hair Trigger gem for managing these in rails.
Trigger would work. But going the pg_notify approach could allow for asynchronous updating whereas the trigger approach could slow writes.
Real-time means latency is predictably within some deadline. But the system he describes is returning wrong answers quickly rather than invalidating stale cache hits and recomputing right answers too slowly.
You could do something similar with built-in ActiveRecord callbacks as well.