Build Serverless Streaming Architectures with Upstash Kafka

How Upstash Kafka is making event streaming serverless while being compatible with Kafka APIs?

Photo by Reza Ghazali on Unsplash

Upstash Kafka: Serverless data for Kafka

Kafka infrastructure is managed for you

Per-request pricing

Getting hands-on with Upstash Kafka

Before you begin

Step 1: Create a Kafka cluster and add a topic

Create a Kafka cluster in Upstash Console
Create a topic with different parameters

Step 2: Produce messages to the cluster

from kafka import KafkaProducer
import json

producer = KafkaProducer(
bootstrap_servers=['Upstash Kafka cluster URL'],
sasl_mechanism='SCRAM-SHA-256',
security_protocol='SASL_SSL',
sasl_plain_username='replace with yours',
sasl_plain_password='replace with yours',
)
order = {
"id" : 124234,
"date": "2022-02-23",
"total": 49.95
}
future = producer.send('orders', json.dumps(order, indent=2).encode('utf-8'))
record_metadata = future.get(timeout=10)
print (record_metadata)
producer.close()
import { Kafka } from "@upstash/kafka"const kafka = new Kafka({
url: "<UPSTASH_KAFKA_REST_URL>",
username: "<UPSTASH_KAFKA_REST_USERNAME>",
password: "<UPSTASH_KAFKA_REST_PASSWORD>",
})
const p = kafka.producer()
const order = {
"id" : 124234,
"date": "2022-02-23",
"total": 49.95
}
const response = await p.produce("orders", order)
View message statistics for a topic

Step 3: Consume messages

from kafka import KafkaConsumer

consumer = KafkaConsumer(
bootstrap_servers=['Upstash Kafka cluster URL'],
sasl_mechanism='SCRAM-SHA-256',
security_protocol='SASL_SSL',
sasl_plain_username='replace with yours',
sasl_plain_password='replace with yours',
group_id='$GROUP_NAME',
auto_offset_reset='earliest',
)
consumer.subscribe(['orders'])
records = consumer.poll(timeout_ms=10000)
print(records)
consumer.close()

Integration with serverless FaaS platforms

Produce and consume events from serverless platforms

Summary

--

--

EdU is a place where you can find quality content on event streaming, real-time analytics, and modern data architectures

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store