pageviews

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Example: page-view counters

A complete Murmur pipeline that ingests page-view events from Kafka, maintains windowed counters per page in DynamoDB (with optional Valkey acceleration), and serves results over a gRPC query service.

This example demonstrates the three principal pieces of Murmur stitched together:

  1. Streaming runtimecmd/worker reads from a Kafka topic and writes to DDB
  2. Cache acceleration — Valkey is configured as a write-through INCRBY-based cache
  3. gRPC query layercmd/query serves Get/GetWindow/GetRange against the same store

Schema

type pageView struct {
    PageID string `json:"page_id"`
    UserID string `json:"user_id"`
}

Pipeline

murmur.NewPipeline[pageView, int64]("page_views").
    From(kafka.NewSource(...)).
    Key(func(e pageView) string { return e.PageID }).
    Value(func(pageView) int64 { return 1 }).
    Aggregate(core.Sum[int64](), windowed.Daily(90 * 24 * time.Hour)).
    StoreIn(dynamodb.NewInt64SumStore(...)).
    Cache(valkey.NewInt64Cache(...)).
    ServeOn(grpc.Config{...})

Run locally

Bring up the docker-compose dependencies:

cd ../..
docker compose up -d kafka dynamodb-local valkey

Run the streaming worker:

go run ./examples/page-view-counters/cmd/worker

In another terminal, run the gRPC query server:

go run ./examples/page-view-counters/cmd/query

Produce some events (using your tool of choice — kcat, a small Go producer, etc.) and then query:

grpcurl -plaintext -d '{"entity": "page-A"}' localhost:50051 murmur.v1.QueryService/Get
grpcurl -plaintext -d '{"entity": "page-A", "duration_seconds": 86400}' \
  localhost:50051 murmur.v1.QueryService/GetWindow

Production deployment

In production each component runs as its own ECS Fargate service. See terraform/ for the deployment module (in progress).

Documentation

Overview

Package pageviews defines the page-view-counters Murmur pipeline. It's imported by both cmd/worker (streaming runtime) and cmd/query (gRPC server) so the two processes share an identical pipeline definition — the same Source/Key/Value/ Aggregate/StoreIn that streamed events get queried with.

Index

Constants

This section is empty.

Variables

View Source
var Window = windowed.Daily(90 * 24 * time.Hour)

Window is the daily-bucket configuration shared by both binaries (otherwise the query side and the streaming side would compute different bucket IDs).

Functions

func Build

func Build(ctx context.Context, cfg Config, withSource bool) (*pipeline.Pipeline[PageView, int64], state.Store[int64], state.Cache[int64], error)

Build constructs the pipeline. The Source is set by the streaming worker; the query server doesn't need a live source and can omit it.

Types

type Config

type Config struct {
	KafkaBrokers  string // comma-separated
	KafkaTopic    string
	ConsumerGroup string

	DDBEndpoint string // empty for real AWS; "http://localhost:8000" for dynamodb-local
	DDBTable    string
	DDBRegion   string

	ValkeyAddress   string // empty to disable cache layer
	ValkeyKeyPrefix string

	GRPCAddr string // e.g. ":50051"
}

Config bundles deployment-time settings the worker and query binaries both need.

type PageView

type PageView struct {
	PageID string `json:"page_id"`
	UserID string `json:"user_id"`
}

PageView is the event shape produced by upstream services.

Directories

Path Synopsis
cmd
query command
Connect-RPC query server for the page-view-counters example.
Connect-RPC query server for the page-view-counters example.
worker command
Streaming worker for the page-view-counters example.
Streaming worker for the page-view-counters example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL