---
title: "Implementing \"seen by\" functionality with Postgres"
description: "Four ways to track post views in Postgres are benchmarked: a naive counter column, an hstore of viewer IDs per post, an association table, and the HyperLogLog extension."
url: "https://swe.quest/articles/implementing-seen-by-functionality-with-postgres-42ef1db52a88742a"
canonical: "https://supabase.com/blog/seen-by-in-postgresql"
source: "Supabase"
published: "2022-07-18"
difficulty: "medium"
kind: "Research"
reading_minutes: 21
tags: ["postgres","data-structures","performance","databases"]
---

# Implementing "seen by" functionality with Postgres

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2022-07-18, 21 min read, Research. Original: [https://supabase.com/blog/seen-by-in-postgresql](https://supabase.com/blog/seen-by-in-postgresql)

## Summary

Four ways to track post views in Postgres are benchmarked: a naive counter column, an hstore of viewer IDs per post, an association table, and the HyperLogLog extension. HyperLogLog is the recommended default because its tradeoffs are good and it adds no large architectural liabilities. hstore is fine for a quick prototype and performed best with integer IDs. The benchmark uses synthetic users and posts with an 80/20 poster skew, replayed through autocannon with a 10/60/30 mix of list-viewers, read-count and record-view requests.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- SQL migrations ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- Postgres extensions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

PostgreSQL, HyperLogLog, hstore, postgresql-hll, autocannon, TOAST

## Related posts

- [London Meetup Report: Scaling Analytics with PostHog and Introducing HouseWatch](https://swe.quest/articles/london-meetup-report-scaling-analytics-with-posthog-and-introducing-housewatch-ed6b50855ec52fa1.md): ClickHouse · 2023-07-05 · Medium · 4 min read · Analytics & OLAP, Performance engineering, Observability, Databases
  PostHog scaled its product analytics platform by moving from Postgres to ClickHouse, with an events table holding roughly 62 TB uncompressed for a single column.
- [Introducing Postgres Query Insights in ClickHouse Cloud](https://swe.quest/articles/introducing-postgres-query-insights-in-clickhouse-cloud-a9697a827409b984.md): ClickHouse · 2026-05-07 · Medium · 7 min read · PostgreSQL, Observability, Performance engineering, Analytics & OLAP
  Postgres Query Insights, now in preview for ClickHouse Cloud Managed Postgres, ranks every normalized query pattern by impact and aggregates per-execution counters (CPU, cache vs disk reads, temp spills, unlaunched parallel workers, WAL) to explain why a pattern is slow.
- [Anatomy of a (Postgres) search engine](https://swe.quest/articles/anatomy-of-a-postgres-search-engine-ef0fff51702b4f16.md): PlanetScale · 2026-09-22 · Medium · 12 min read · Search, PostgreSQL, Data structures, Storage engines
  Inverted indexes power full-text search by mapping each term to a sorted, compressed postings list of document IDs, with optional positional data for phrase/span queries and frequency statistics for BM25 scoring.
- [PostgreSQL Stories: From slow query to fast—via stats](https://swe.quest/articles/postgresql-stories-from-slow-query-to-fast-via-stats-ac7001ab0fde8224.md): Render · 2024-05-14 · Medium · 13 min read · PostgreSQL, Query engines, Performance engineering, Debugging
  A simple LIMIT 1 join between a ~100k-row postgres\_dbs table and a ~90M-row events table ran for hours.
- [LangChain - Why we Choose ClickHouse to Power LangSmith](https://swe.quest/articles/langchain-why-we-choose-clickhouse-to-power-langsmith-5117f6fe7184a57a.md): ClickHouse · 2024-04-23 · Medium · 9 min read · Analytics & OLAP, Observability, LLMs, PostgreSQL, Databases
  LangSmith, LangChain's LLM observability and evaluation platform, began fully on Postgres but outgrew it as users logged most of their production traces: ingestion lagged, precomputed materializations were rigid and costly, and lock contention grew.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
