𝗨𝘀𝗶𝗻𝗴 𝗦𝘂𝗿𝗿𝗲𝗮𝗹𝗗𝗕 𝗚𝗿𝗮𝗽𝗵 𝗤𝘂𝗲𝗿𝗶𝗲𝘀 𝗳𝗼𝗿 𝗩𝗶𝗱𝗲𝗼 𝗥𝗲𝗰𝗼𝗺𝗺𝗲𝗻𝗱𝗮𝘁𝗶𝗼𝗻𝘀

Our recommendation logic used to be a 280-line SQLite query. It used six self-joins to find what a user should watch next.

The goal was simple: find videos watched by people who watched this video. We wanted to weigh these results by recency and region.

We forced a graph problem through a relational engine. This caused problems:

Relational models are not wrong, but they were the wrong shape for our data. Recommendations are graph problems. Users, videos, and tags are nodes. Watching or tagging are edges.

We moved this single subsystem to SurrealDB. We kept our PHP 8.4 and SQLite stack for everything else. The results changed immediately:

How it works: Collaborative filtering via traversal follows these steps: • Find users who watched video A. • Find other videos those users watched. • Rank them by frequency, recency, and region.

In SQL, this requires multiple joins through a table. In SurrealDB, it is a single traversal because the edges act as the index.

We also solved for GDPR compliance: • We do not store personal identifiers on the graph. • A viewer is a pseudonymous session token with an expiration date. • We use Cloudflare to detect region without storing IP addresses. • This follows the principle of data minimization.

The architecture is lean. We use SurrealDB as a derived, disposable store. If it fails, we replay events from our logs. We use a Cloudflare Worker to cache results for 90 seconds. This prevents a surge of requests from hitting our database.

The lesson is not that graph databases are always faster. It is that modeling graph problems relationally creates a performance tax. If you have a query that uses many joins to follow relationships, consider isolating it.

Source: https://dev.to/ahmet_gedik778845/using-surrealdb-graph-queries-to-power-video-recommendations-303c