Cloud event specification ( a first look)

Olawepo Olayemi
3 min readApr 18, 2022

--

In the last few months I have been working on projects with event driven architecture (EDA), during these periods I have seen those projects freestyle in the ways which events are described and the formats in which they are delivered. So I decided to research for a more standard specification acceptable across the industry to describe “events” and I found cloudevents specification very useful.

CloudEvents is a specification for describing event data in a common way, see more details on thier page cloudevents.

cloudEvents is part of the Cloud Native Computing Foundation’s Serverless Working Group (CNCF).

An event is a change in state, or an update, like an item being placed in a shopping cart on e-shop. Events can can be sateful i.e carries the state (the item purchased, its price, and a delivery address) or stateless i.e events can be identifiers (for example a notification that an item has been processed).

Key components of EDA are event producers, broker/router and consumer(s). event producer publishes event to a broker which acts as an exchage to route events to subscribed consumers.

Describing events that will flow through such system using cloudevents we can go through steps 1 — 3. ( see details of the specs here)

1. Developer questions ?

  • What kind of event ? type
  • When was it sent? Time
  • Who sent it? Source
  • What is the event unique identifier ? id
  • What is the shape of the event data? Data schema
  • What is the event data ? data

2. Formats for cloud events:

Cloudevents has binary and structured encodings for event payloads, Binary is when the protocol supports separation of message metadata from its data and when the protocol encodes the data and metadata together into a structured object, then the message is structured.

2.1 HTTP Binary

POST /event HTTP/1.0 
Host: oentity.com
Content-Type: application/json
ce-specversion: 1.0,
ce-id: ac0ee0e5-2c25-493c-8328-c661724d3f0e,
ce-source: com.oenity/consent,
ce-type: com.oenity.raw,
ce-time: 2022-04-18T16:02:30.187640+00:00
{
'id': '1',
'action':'opt-in'
}

2.2 HTTP Structure

POST /event HTTP/1.0 
Host: oentity.com
Content-Type: application/cloudevents+json
{
"specversion": "1.0",
"id": "7dea11de-e602-47d1-abc9-f44a982d66eb",
"source": "https:oentity.com/consents",
"type": "com.oenity.raw",
"time": "2022-04-17T00:21:25.967655+00:00",
"data": "{'id': '1', action':'opt-in'}",
"eventid": "de26f085-dee9-4bc6-a71c-815f23023d2d"
}

3. Example cloud events SDKs
To generate standard cloud event there are SDKs that can be used and it supports several languages like Go, javascript, java, C#, Ruby, PHP, Python, Rust, Powershell.

See python sdk example to generate binary and structured event;

install the cloevents sdk by running;

pip install cloudevents

call each the functions from above file to get event payload similar to ones below;

For binary, you should see something like this, with hearders similar to formats shown in above section 2.1

{
'id': '1',
'action':'opt-in'
}

and for structured, you should see something like this

{
"specversion": "1.0",
"id": "1480020a-4a8d-4208-a5cd-2dd783383e42",
"source": "com.oenity/consent",
"type": "com.oenity.raw",
"time": "2022-04-18T16:14:39.995534+00:00",
"data": "{'id': '1', 'action':'opt-in'}",
"eventid": "de26f085-dee9-4bc6-a71c-815f23023d2d"
}

cloudevents specification may be what you are looking for, If you are working on system(s) that produce(s) / consumes and broker event data in several formats accross multiple protocols with several consumers/subscribers.

--

--

Olawepo Olayemi

SW Generalist, Test Automation engineer, Technology enthusiast and entrepreneur. I Love Python and brewing my own beer (IPA usually).