Cloud.Kafka
A managed Kafka cluster in KRaft mode, with one or three equal brokers.
Every connection uses TLS and SASL (SCRAM-SHA-512); topics and users are
KafkaTopic and KafkaUser (clients can’t create topics).
Deploying blocks until the cluster is running (up to 30 minutes), and
fails with a typed WaitFailed when it ends failed or degraded, or
WaitTimeout past the budget.
Plans and versions. type is the plan per broker, KA1 (4 vCPU,
4 GB, 64 GB, 250 partitions) to KA8; Cloud.listKafkaType lists them.
engineVersion is the Kafka major.minor version, such as 4.4;
Cloud.listKafkaVersion lists them. brokerCount is 1 (development) or
3 (survives the loss of a broker); every broker bills at the plan’s price.
Billing. term is monthly (the default) or annual: annual
commits you to a year of the plan (the API: “Paid for a year”). A
change of term applies at once and starts a new term.
What changes in place. name, metadata, publicAccess and term
update in place; type rescales and engineVersion upgrades, each through
its own action, and the deploy waits until the cluster is running on the
new value; networkIds and firewallIds (at most one firewall: a swap
detaches the old one first) attach and detach one at a time.
brokerCount, teamId and availabilityZone replace the cluster, which
deletes its data (Kafka clusters have no snapshots): a replace that keeps
an explicit name deletes the old cluster first.
Connecting. bootstrapServers / publicBootstrapServers,
securityProtocol, saslMechanism, the default user’s username and
password, caCertificate and the ready-made client properties come
from the credentials endpoint, read once the cluster is running.
Applications should rather sign in as their own KafkaUser, whose
attributes carry the same settings with its own password. Secrets are
Redacted.
Credentials: the deploy never rotates them on its own. Set
rotateCredentials to a new value to rotate the default user’s
password once; a rotation done in the console or CLI is read on the next
deploy, without a replace.
Creating a cluster
Section titled “Creating a cluster”Three brokers on a private network
const network = yield* BetterStack.Cloud.Network("private", { ipPrefix: "10.0.0.0", ipPrefixLength: 24,});const events = yield* BetterStack.Cloud.Kafka("events", { type: "KA1", brokerCount: 3, networkIds: [network.id],});Topics and users
Section titled “Topics and users”A topic and a user that produces to it
const kafka = yield* BetterStack.Cloud.Kafka("events", { type: "KA1", brokerCount: 3 });yield* BetterStack.Cloud.KafkaTopic("orders", { kafkaId: kafka.id, name: "orders", partitions: 6,});yield* BetterStack.Cloud.KafkaUser("producer", { kafkaId: kafka.id, username: "orders-producer", privileges: [{ topicPattern: "orders", permission: "produce" }],});Connecting
Section titled “Connecting”A Cloud.Service producing with its own user
const producer = yield* BetterStack.Cloud.KafkaUser("producer", { kafkaId: kafka.id, privileges: [{ topicPattern: "orders", permission: "produce" }],});// In the Service's props:// env: {// KAFKA_BROKERS: producer.bootstrapServers,// KAFKA_USERNAME: producer.username,// KAFKA_PASSWORD: producer.password,// KAFKA_CA: producer.caCertificate,// }Looking up an existing cluster
Section titled “Looking up an existing cluster”Reference a cluster by id
const existing = BetterStack.Cloud.Kafka.lookup({ id: "42" });Reference a cluster by name (fails with AmbiguousLookup when several share it)
const byName = BetterStack.Cloud.Kafka.lookup({ name: "events" });type string required
The cluster's type, such as KA1.
availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
brokerCount number
The number of brokers, 1 for development or 3 to survive the loss of a broker. Can't be changed after the cluster is created.
engineVersion string
The Kafka version as major and minor, such as 4.4.
firewallIds string[]
The ID of the firewall attached to every broker, at most one.
metadata CreateKafkaRequestMetadataMap
Your tags, as an object of string keys and values. An update replaces every tag.
name string
The cluster's name, up to 255 characters, unique among the organization's clusters that aren't failed or destroyed. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.
networkIds string[]
The IDs of your networks attached to every broker.
publicAccess boolean
Whether the cluster also has public endpoints. Clients connect with TLS and SCRAM on both the private and the public endpoints.
rotateCredentials string
Rotate the credentials: every change of this value after create (for example a date, "2026-12") calls the API's rotate operation once on the next deploy, and the new secrets replace the old ones in the attributes (and so in every env that references them). Leaving it out, or keeping the same value, never rotates. A rotation done in the console or CLI is simply read on the next deploy.
teamId string
Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.
term "monthly" | "annual" | string
The billing term. Defaults to monthly. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
bootstrapServers string always set
The private bootstrap address, host:port on 9092 (endpoint.bootstrapServers). Clients must reach every broker too (endpoint.brokers), not only this address. undefined until provisioned.
caCertificate string always set
The CA certificate bundle (PEM) that signs the brokers' TLS certificates.
id string always set
The cluster's ID.
password Redacted<string> always set
The default user's SCRAM password (credentials password).
properties KafkaClientProperties always set
The client settings under the names librdkafka, kcat and most Kafka clients use (bootstrap.servers, security.protocol, sasl.mechanism, sasl.username, sasl.password, ssl.ca.location); sasl.password is Redacted. Point ssl.ca.location at a file holding caCertificate.
publicBootstrapServers string always set
The public bootstrap address on 9095 (endpoint.publicBootstrapServers), undefined unless publicAccess is on.
saslMechanism string always set
The client sasl.mechanism, SCRAM-SHA-512 (endpoint.saslMechanism).
securityProtocol string always set
The client security.protocol, SASL_SSL (endpoint.securityProtocol).
username string always set
The default user's username, undefined when the cluster has none (credentials username).
availableEngineVersions string[]
The version you can upgrade the cluster to, the next one we offer. The list is empty when the cluster runs the newest version.
brokerCount number
The number of brokers, 1 for development or 3 to survive the loss of a broker. Can't be changed after the cluster is created.
brokers KafkaBrokersItem[]
The cluster's brokers, with their addresses on your networks and their last reported health. All brokers have the same role.
createdAt string
When the cluster was created.
endpoint KafkaEndpoint
The addresses clients connect to, the bootstrap address and one for each broker. The fields that start with public_ are only present when public_access is on. Clients must reach every broker, not only the bootstrap address.
enginePatchVersion string | null
The exact Kafka release installed, such as 4.4.0.
engineVersion string
The Kafka version as major and minor, such as 4.4.
firewallIds string[]
The ID of the firewall attached to every broker, at most one.
maxPartitions number
The most partitions the cluster's type allows across all topics.
metadata KafkaMetadataMap
Your tags, as an object of string keys and values. An update replaces every tag.
minInsyncReplicas number
The number of copies that must confirm a write, 1 with one broker and 2 with three.
name string
The cluster's name, at most 255 characters, unique among your organization's clusters that aren't destroyed or failed.
networkIds string[]
The IDs of your networks attached to every broker.
partitionCount number
The number of partitions across all topics.
publicAccess boolean
Whether the cluster also has public endpoints. Clients connect with TLS and SCRAM on both the private and the public endpoints.
replicationFactor number
The number of copies of each partition, always equal to broker_count. Every broker stores every partition.
status string
The cluster's state. - provisioning: We're starting the brokers and installing Kafka. - running: The cluster is ready. Right after it's created, brokers can still be starting. - degraded: A broker is down, partitions are missing copies or a disk is almost full. status_message says which. - rescaling: We're changing the cluster's type. - upgrading: We're upgrading the cluster to a newer Kafka version. - failed: We couldn't create the cluster. status_message says why. - destroyed: The cluster is destroyed.
statusMessage string | null
Why the cluster is in its current state, such as which broker is down, or null when there's nothing to report.
storageBudgetBytes number
The storage budget of each broker, in bytes. Every topic must fit in it.
storageBudgetUsedBytes number
The storage your topics reserve, in bytes. Each topic reserves its retention_bytes times its number of partitions, plus one segment for each partition.
teamId string
The ID of the team that owns the cluster. Can't be changed after the cluster is created.
term "monthly" | "annual"
The billing term. Defaults to monthly. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.
topics KafkaTopicsItem[]
The cluster's topics, ordered by name. Add, update or remove them with betterstack kafka-topic.
type string
The cluster's type, such as KA1.
updatedAt string
When the cluster was last updated.
usableStorageGb number
The storage for your topics on each broker, in GiB.
users KafkaUsersItem[]
The cluster's users, ordered by username. Add, update or remove them with betterstack kafka-user, which also gets their passwords.
Lookup
Section titled “Lookup”Kafka.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
availabilityZone string
Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.
See also
Section titled “See also”- Ownership. Every object the stack creates carries an
alchemyentry in itsmetadata(<stack>/<stage>/<resource id>#<instance>), added on every write and left out of the attributes and of diffs; your own keys are untouched (it takes one of the 10 slots). A deploy that lost track of an object it created (a create that failed or timed out after the API accepted it) finds it by that marker and converges it instead of creating another;list(and soalchemy nuke) returns only Alchemy-created objects; an object with the same name but no marker of this resource is taken over only with--adopt. - https://betterstack.com/docs/cloud/api/kafkas/credentials-kafka/