The Simplest Way to Make Cloud SQL and Kafka Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Pairing cloud sql and kafka lets teams stream database changes to event pipelines in real time. This setup sends row updates from your managed relational tables straight to downstream apps. Transactional databases store your core state. Event streams move that state to search indexes, analytics stores, and microservices. When both systems work together, your apps react to new data right away. You do not need slow batch jobs to sync your systems. How cloud sql and kafka share permissions and d

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Pairing cloud sql and kafka lets teams stream database changes to event pipelines in real time. This setup sends row updates from your managed relational tables straight to downstream apps.

Transactional databases store your core state. Event streams move that state to search indexes, analytics stores, and microservices. When both systems work together, your apps react to new data right away. You do not need slow batch jobs to sync your systems.

How cloud sql and kafka share permissions and data

Data flows from your database to your message topics through change data capture or polling. In Cloud SQL for PostgreSQL, customers cannot create or access users with true superuser attributes. A Google-managed system user holds actual superuser privileges on the database. Instead, you use a built-in admin role with specific high-level privileges. This role lets you create replication users and set up replication publications and subscriptions.

The default admin user belongs to this high-level role and can create roles and databases. Still, that default admin user does not have replication attributes by default. To stream changes out, an admin first creates a dedicated replication user and a publication. Your streaming connector then logs in with that replication user to read the database write-ahead log. As rows change, the connector reads the stream and writes events to your message topics.

This flow also works in reverse when topics feed data back into tables. A sink worker reads records from a topic and runs insert or update queries. That worker only needs write permissions on specific target tables. Keeping source and sink roles separate keeps your data flow clean and easy to trace.

Common failure modes and how to scope roles

Many teams use the default admin account to run their streaming workers. This is a big risk because that account can create new roles and databases. If a worker key leaks, an attacker gains broad control over your database instance. Shared service accounts also make it hard to see who ran a bad query.

Engineers also run into trouble when debugging broken streams in production. When a topic falls behind, a developer might log into the database using shared admin keys. Unlogged queries and manual table fixes can break replication state or leak sensitive fields. If a table holds emails, phone numbers, or card numbers, raw queries expose that data.

End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix these issues by scoping every role to a single task. Create one database user just for reading replication publications. Create a second user with narrow write rules for sink workers. Never share these machine credentials with human engineers who inspect the system. Route all network traffic over private virtual networks so public endpoints stay closed. When humans need to check table state or topic offsets, give them separate, limited accounts. Masking rules can also rewrite emails or national IDs in query results during fixing.

Keeping human debugging separate from machine streams

Machine pipelines need steady links to move events every second. Human engineers only need short sessions to check replication lag or inspect a bad row. Mixing these two access patterns causes most security gaps in event-driven setups.

Set up clear rules for how your team checks both systems during an incident. Engineers should log in with their own work identities instead of copying connector passwords. Every manual query against a source table should go into an audit log. This habit keeps your streaming pipeline fast while keeping your customer data safe.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Can I use a true PostgreSQL superuser to set up replication in Cloud SQL?

No, customers cannot create or use accounts with true superuser attributes in this managed service. You must use the built-in cloudsqlsuperuser role to create replication users and publications.

Does the default postgres admin user have replication rights out of the box?

No, the default postgres user does not come with replication attributes enabled. It also starts without a password, so you must set one and grant specific roles first.

Why should teams avoid using the default admin account for streaming connectors?

The default admin account can create databases and roles across the whole instance. Using a scoped user limits damage if a connector key leaks and keeps audit logs clear.

The query runs. The emails stay hidden.