cancel
Showing results for 
Search instead for 
Did you mean: 
Technical Blog
Explore in-depth articles, tutorials, and insights on data analytics and machine learning in the Databricks Technical Blog. Stay updated on industry trends, best practices, and advanced techniques.
cancel
Showing results for 
Search instead for 
Did you mean: 
grpeternel
Databricks Employee
Databricks Employee

Streaming raw events into a cyber lakehouse and normalizing them to a standard schema is a common pattern for security analytics. This blog walks through an end-to-end architecture that uses Databricks Zerobus to push events into a bronze Delta table, Spark Declarative Pipelines (SDP) to process them through a medallion architecture, and the Open Cybersecurity Schema Framework (OCSF) for gold-layer analytics. OCSF gold tables unlock downstream cyber use cases by consolidating diverse raw logs into a common information model organized by OCSF cybersecurity category and event class. Instead of dozens of siloed tables per vendor or source, you get one table per class that unifies all relevant events, so analysts can run simple filters and find patterns and insights across sources. For a full look at how Databricks is bringing these capabilities together into an open, agentic SIEM, see Databricks Lakewatch.

Zerobus Ingest

Zerobus Ingest is Databricks' managed high-throughput ingestion service for streaming records directly into Delta tables. A producer (e.g., a Python script) uses the Zerobus SDK to send batches of records to a workspace endpoint; Zerobus writes them into the target table without you running a separate Spark streaming job for the ingest. That makes it a good fit for API-driven sources (webhooks, REST APIs, event feeds) that require low-latency, push-based writes to the lakehouse. Tables must live in a Unity Catalog location with a managed storage path; the producer authenticates via a service principal and sends records that match the table's schema (including standard metadata columns such as event time and source) with support for the variant data type.

Spark Declarative Pipelines (SDP)

Spark Declarative Pipelines define streaming ETL as Python functions decorated with SDP annotations or as SQL queries. You declare sources (e.g., views or streaming tables), transformations, and sinks; the Lakeflow Spark Declarative Pipelines runtime compiles them into a single pipeline DAG and runs them as jobs. SDP supports streaming tables, append flows into Delta sinks (other sink types are supported as well), and clustering and table properties, so you can implement a medallion (bronze → silver → gold) pattern entirely in code. Point the pipeline at a folder of Python or SQL modules and start it; all layers stay in sync incrementally.

OCSF

A common challenge in data engineering for cybersecurity is the sheer diversity of raw security logs: different formats and schemas for the same data, many vendors (e.g., AWS, Microsoft Defender, Okta, Palo Alto Networks), and a mix of categories (application, system, IAM, network) and event classes (API, file, auth, DNS, and more). A reusable blueprint that normalizes this variety into a single standard can scale across sources, cut pipeline development time, automate OCSF mapping, and speed delivery to customers while keeping a consistent, resilient data architecture.

The Open Cybersecurity Schema Framework is a vendor-neutral schema for security and observability events. OCSF defines categories (e.g., System Activity, Findings, Identity & Access Management, Network Activity, Application Activity) and event classes (e.g., Process Activity, Detection Finding, HTTP Activity) with standard field names, types, and semantics. Normalizing raw logs into OCSF makes it easier to run cross-source analytics, build reusable dashboards, and plug into SIEMs, SOARs, and SOC workflows that consume OCSF. In this example, we map public GitHub events into three OCSF v1.7.0 classes: API Activity (6003), Entity Management (3004), and File System Activity (1001).

E2E Cyber Lakehouse Streaming Architecture

For demo simplicity, this example streams public GitHub events, which require no authentication. In practice, this same pattern applies to any device or cyber event API — most production sources will require an authentication access token or an OAuth setup in the producer.

The flow is: GitHub Events API → Zerobus Ingest → Bronze Delta table → SDP Silver (flattened) → SDP Gold (three OCSF Delta sinks).

grpeternel_0-1776115366777.png

Prerequisites:

  • A Unity Catalog catalog and schemas with managed storage locations
  • A bronze Delta table created via DDL
  • The three OCSF gold tables created via DDL
  • A Zerobus Ingest producer that writes into bronze

The SDP pipeline source is the folder containing the pipeline Python modules; it reads from the bronze table (exposed as a view), builds a silver streaming table, and then appends to the three gold sinks. Below are focused code snippets for each layer.

1. Zerobus Ingest: Writing to the Bronze Table with Standard Meta Fields

The producer (e.g., push_zerobus.py) authenticates via a service principal, initializes the Zerobus SDK with the target table and record type, and creates a stream.

from zerobus.sdk.sync import ZerobusSdk
from zerobus.sdk.shared import RecordType, StreamConfigurationOptions, TableProperties

CLIENT_ID = dbutils.secrets.get(scope=ZEROBUS["secrets_scope"], key="client-id")
CLIENT_SECRET = dbutils.secrets.get(scope=ZEROBUS["secrets_scope"], key="client-secret")

sdk = ZerobusSdk(ZEROBUS["endpoint"], ZEROBUS["workspace_url"])
table_props = TableProperties(FQN["bronze"])
options = StreamConfigurationOptions(record_type=RecordType.JSON)

stream = sdk.create_stream(CLIENT_ID, CLIENT_SECRET, table_props, options)

From there, it fetches events, builds one record per event, and sends batches via stream.ingest_records_nowait() and stream.flush(). Each record includes the raw payload plus standard metadata fields that match the bronze table: event_time, event_date, source, source_type, source_path, and processed_time.

def build_bronze_record(event: dict) -> dict:
    created_at = event.get("created_at", datetime.now(timezone.utc).isoformat())
    return {
        "data": json.dumps(event),
        "event_time": _epoch_micros(created_at),
        "event_date": _epoch_days(created_at),
        # metadata fields — must match bronze table schema
        "source": GITHUB["source"],
        "source_type": GITHUB["source_type"],
        "source_path": GITHUB["events_url"],
        "processed_time": _now_micros(),
    }

The producer sends event_time and event_date as epoch values (micros and days); the target table defines them as TIMESTAMP and DATE, and Zerobus Ingest (or the ingest path) handles the conversion. The bronze table DDL includes a VARIANT column for the raw payload and the same metadata columns so that downstream pipelines and OCSF metadata can use them consistently:

CREATE TABLE IF NOT EXISTS cyber_lakehouse.github.github_events_bronze (
    data            VARIANT,
    event_time      TIMESTAMP,
    event_date      DATE,
    source          STRING,
    source_type     STRING,
    source_path     STRING,
    processed_time  TIMESTAMP
)
USING DELTA
CLUSTER BY (event_time)
TBLPROPERTIES ('delta.feature.variantType-preview' = 'supported');  -- required on older runtimes
-- also set: spark.databricks.delta.preview.enabled = true (cluster Spark conf)

2. Silver: Flattening the Variant into a Typed Streaming Table

The SDP silver layer reads from the bronze table (via the temporary view) and flattens the VARIANT data column using Spark SQL variant path notation (data:field.subfield::type). For fields with inconsistent or malformed values, prefer try_variant_get(data, 'field', 'type') over the ::type cast — it returns NULL instead of raising an error, which keeps the pipeline running on noisy or partial event payloads. The result is a streaming table with strongly typed columns (event_id, event_type, actor*, repo, payload_, etc.) plus the original data, source, source_type, and processed_time for downstream use and OCSF raw_data.

@sdp.table(
    name=TABLES["silver"],
    cluster_by=["event_date"],
    table_properties=TABLE_PROPERTIES,
)
def github_events_silver():
    return (
        spark.readStream
        .table(TABLES["bronze"])
        .selectExpr(
            "data:id::string                    AS event_id",
            "data:type::string                  AS event_type",
            "event_time",
            "event_date",
            "data:actor.id::long                AS actor_id",
            "data:actor.login::string           AS actor_login",
            "data:actor.url::string             AS actor_url",
            "data:repo.id::long                 AS repo_id",
            "data:repo.name::string             AS repo_name",
            "data:repo.url::string              AS repo_url",
            "data:payload.ref::string           AS payload_ref",
            "data:payload.ref_type::string      AS payload_ref_type",
            "data:payload.commits::string       AS payload_commits_json",
            "data:payload.distinct_size::int    AS payload_distinct_size",
            "data",
            "source",
            "source_type",
            "source_path",
            "processed_time",
        )
    )

3. Gold: Multiple Delta Sinks as OCSF Tables

We use append-only Delta sinks (pre-created Delta tables) for the OCSF gold layer instead of SDP-managed streaming tables because SDP tables are owned by and tied to a single pipeline. With OCSF, you typically want multiple pipelines — e.g., one per source or vendor — writing into the same OCSF tables (e.g., one shared api_activity table). Pre-created Delta tables act as independent sinks that any pipeline can append to via create_sink and append_flow, so you get a single, shared OCSF gold layer across all pipelines.

The gold layer defines one append flow per OCSF event class, each writing to one of these pre-created Delta tables. SDP's create_sink binds a logical sink name to a Delta table FQN; @sdp.append_flow(target=...) connects a streaming DataFrame to that sink. Each flow reads from the silver streaming table, maps columns to OCSF fields (class_uid, category_uid, activity_id, actor, metadata, raw_data, unmapped, etc.), and appends to the corresponding gold table.

Sink declaration and one example flow (API Activity) are below. The pipeline maps GitHub event_type to OCSF activity_id / activity_name using CASE expressions (e.g., CreateEvent → Create, PushEvent → Update). Entity Management and File System Activity follow the same pattern with different filters and OCSF field mappings.

sdp.create_sink(
    name="api_activity",
    format="delta",
    options={"tableName": FQN["api_activity"]},
)

@sdp.append_flow(target="api_activity")
def api_activity_flow():
    return (
        spark.readStream
        .table(TABLES["silver"])
        .selectExpr(
            "6003 AS class_uid",
            "'API Activity' AS class_name",
            "6 AS category_uid",
            "'Application Activity' AS category_name",
            "event_time AS time",
            "event_date",
            "named_struct('user', named_struct('name', actor_login, 'uid', CAST(actor_id AS STRING), 'url', actor_url)) AS actor",
            "named_struct('operation', event_type, 'service', named_struct('name', 'GitHub')) AS api",
            "named_struct('name', repo_name, 'uid', CAST(repo_id AS STRING), 'url', repo_url) AS resources",
            "CONCAT(actor_login, ' performed ', event_type, ' on ', repo_name) AS message",
            "CAST(to_json(named_struct('payload', data, 'source', source, 'sourcetype', source_type)) AS VARIANT) AS raw_data",
            # ... metadata (version, product, log_provider, processed_time, logged_time), status, severity, unmapped
        )
    )

Entity Management filters to CreateEvent, DeleteEvent, ForkEvent, ReleaseEvent, and PublicEvent, and maps to the OCSF entity and activity fields; File System Activity filters to PushEvent and maps branch/ref and commit info into the file and message fields. All three gold tables are created in advance using OCSF-aligned DDL (see the repo's ddl_ocsf.py).

Here is an example of how to query across distinct vendors and log types in a single OCSF gold table:

SELECT *
FROM cyber_lakehouse.ocsf.api_activity
WHERE metadata.log_provider = 'github'
  AND metadata.log_name     = 'events'
  AND api.operation         = 'PushEvent'
  AND time                  >= current_timestamp() - INTERVAL 1 DAY;

When you change the OCSF gold schema or mapping logic, you can reset checkpoints for individual streaming flows instead of running a full refresh on the entire pipeline. This avoids reprocessing bronze and silver and only replays gold. Before triggering the reset, delete the existing gold table data for that source via Delta Lake — otherwise the replay will produce duplicate records. Use the fully qualified table name (catalog.schema.table, i.e., cyber_lakehouse.ocsf.api_activity) as the flow name:

curl -X POST \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "reset_checkpoint_selection": ["catalog.schema.table"]
  }' \
  https://<workspace>/api/2.0/pipelines/<pipeline-id>/updates

Scale Further with Lakewatch

This blog demonstrates one approach to building a cybersecurity streaming pipeline from scratch, but maintaining accurate OCSF mappings across the variety of vendor sources and log types quickly becomes time-consuming and complex.

Databricks announced Lakewatch. It provides a data normalization marketplace with ready-made mappings for a wide variety of security vendor sources and log types, covering detection, alerting, investigation, and response use cases — all built natively on the Databricks Data Intelligence Platform.

If you are interested in learning more, reach out to your Databricks account team.

Conclusion

Using Zerobus Ingest for push-based bronze ingestion, SDP for a declarative medallion pipeline, and OCSF for gold tables gives you a clear path from external events to normalized, queryable security events in the lakehouse. You keep a single pipeline definition, standard metadata on every record, and the flexibility to onboard additional sources or OCSF classes by following the same pattern — one new producer and one new set of append flows. See the references below for Databricks cybersecurity lakehouse best practices and related blog posts.

Thank you for reading this blog. The full example (Zerobus producer, DDLs, and SDP pipeline) is available in the Zerobus Ingest Examples repo.

References