Back to blog

Blog

How Dioveo runs on Rivestack: pooler, TLS and pgvector

An engineering story from a product that runs two Postgres databases on Rivestack: why managed Postgres, what a transaction-mode pooler changed in the Go driver setup, how certificate checking was kept simple, and how pgvector is used for search.

PostgreSQLpgvectorcustomer story

Rivestack and Dioveo have the same founder. That makes this a story about our own product on our own platform, so treat it as a field report and not as an independent review. The details below come from Dioveo's code and deployment files. This post leaves out hostnames, settings and numbers on purpose.

Dioveo downloads email attachments from Gmail and Outlook, and offers search over the text of those attachments, with semantic search on the Pro plan. Behind that sits a handful of services. Two of them keep their state in Postgres on Rivestack: the Hub and the Content service.

What Dioveo stores#

The Hub keeps connection records for linked mail accounts. Each record holds the provider, the integration type, a refresh token that is encrypted before it is stored, a failure counter, a lock timestamp and a JSON column for extra provider data. The code guards those rows carefully: a returning login that finds a row busy writes nothing to it.

The Content service stores extraction work. It keeps job rows, page-aware text chunks with a generated tsvector column and a GIN index, and a set of semantic search tables: documents, passages, 1024-dimension vectors, leased tasks, a usage ledger and search sessions. Source deletion cascades to the derived passages and vectors, which is simpler to enforce when everything is in one transactional store.

Why managed Postgres#

The short reason is that we wanted to spend engineering time on the product and not on failover. The Content service's production deployment notes list what to confirm on the managed cluster before launch: more than one node with automatic failover, point-in-time recovery, off-node backups, a tested restore and alerts. Those are checks on a managed service. On a self-run cluster they would be projects.

One detail from the Kubernetes side shows how this changes the setup. The database address is a managed DNS name with a short TTL, so it can move during a failover. A Kubernetes NetworkPolicy cannot match on a DNS name, and pinning an IP address would break on the first failover. The policy therefore allows database traffic by port and not by address, and relies on TLS host name checking to make sure the connection reaches the right server.

The pooler lesson in pgpool.go#

The Hub connects through Rivestack's transaction-mode pooler, and that needed one driver setting. The Hub is written in Go and uses lib/pq. By default, a parameterized query in that driver goes to the server in more than one step. In transaction mode, the pooler can hand the server connection to another client between those steps. The next step can then land on a backend that never saw the first one.

The fix is a single connection option, binary_parameters. The comment in the code says what it buys: every query becomes one atomic protocol batch, so the pooler cannot reassign the backend between Parse and Bind. Parse, Bind and Execute travel together.

It comes with a side effect. With that option, lib/pq sends []byte arguments in binary format. That is right for bytea columns and wrong for jsonb. The code handles this in the type that wraps the JSON column: its Value method returns a string and not bytes, and a comment explains why. The rule we ended up with is short. Bytes go to bytea columns only. JSON goes as a string.

If you run a Go service through a transaction pooler, this is the checklist we would give you:

  1. Use the driver option that makes each query a single batch.
  2. Bind JSON as a string.
  3. Add a test that runs real queries through the pool, because the failure only shows up when a pooler is in the path.

The same file holds a second lesson that has nothing to do with the pooler. A half-open TCP connection (for example after a node reboot or a pooler restart) can leave lib/pq waiting for a reply for a very long time, because it reads answers with no deadline. The Hub dials with TCP keepalive tuned to notice a dead peer within about a minute, sets a ceiling on a single socket read, and ends a blocked read when the caller's context ends. The tests cover a half-open connection, a stalled handshake and a connection that is not reused after an abort. A pooler restart is a normal event, so this was worth building.

The TLS certificate detail#

Production checks both the database certificate and the host name, and the Hub refuses to start if it is told to do less. The check is in the configuration code, and a loopback database is the only exemption. In staging and other environments a weaker setting starts with a warning.

The values file records two decisions that made this easy:

  • The managed database host presents a certificate from a public certificate authority. The system root certificates therefore verify it, and the chart's field for a custom root certificate stays empty. No private CA bundle has to be mounted or rotated.
  • The setting is written as a literal in the chart and not inherited from the secrets manager. A literal in the chart takes precedence over inherited values, so no inherited value can weaken it. The schema migration job, which runs as a Helm pre-upgrade hook, uses the same literal and verifies against the Java trust store.

What this solved is drift. An edited secret does not quietly turn production into an unverified connection, and the migration path matches the application path.

How pgvector is used in production#

Semantic search lives in the Content service and runs on its dedicated Rivestack database. Migration 0008 enables the vector extension and creates a table with a VECTOR(1024) column. Embeddings come from Cohere Embed v4 on Amazon Bedrock in the EU, and queries rank by cosine similarity. Local and CI databases use the pgvector Postgres image, so tests run the same SQL.

Three choices in the pgvector code are worth copying:

  • Exact search first. There is no ANN index yet. A comment in the migration says to add one only after measuring recall and latency with tenant filters, because a global ANN index can starve small tenants. Queries filter by account first, then rank by cosine distance, so the exact scan covers a small slice.
  • Hybrid ranking. Semantic and keyword candidates are merged with reciprocal rank fusion. The keyword half uses the generated tsvector column and a GIN index, and the semantic half uses the <=> operator. Each side contributes a bounded candidate window.
  • Lifecycle in SQL. Vectors are tied to their passages with a cascading foreign key. Deleting a source deletes its vectors. A late result from the embedding provider is discarded and not stored if the user has withdrawn consent in the meantime, and a test covers that case.

What we would tell another team#

Use the pooler, and test through it from the first day. Keep TLS checking strict and make the certificate path boring by using a public CA. Start pgvector with exact search and filters, and add an index when you have measured a need.

If you are choosing a Postgres host for similar work, Rivestack has guides on connection pooling and hybrid search with pgvector.

Keep reading