Skip to content

"Asami: Turn your JSON into a Graph in 2 Lines" by Paula Gearon

Paula Gearon

CommunityStrange Loop Conference43 minBeginnerOpen on YouTube ↗

Engineers explore architecture and security mechanisms for "Asami: Turn your JSON into a Graph in 2 Lines" by Paula Gearon.

Summary

### Overview In this talk, Paula Gearon, a Technical Leader at Cisco Systems, introduces Asami, an open-source graph database developed in Clojure and ClojureScript. Gearon details the background and motivations behind Asami's creation, the mathematical foundations of graph databases, and how Asami's storage and indexing architecture enables fast in-memory and durable querying. She highlights how Asami handles flexible, schema-less JSON imports in just two lines of code and shares real-world use cases, including integration into Cisco's SecureX security product and inspecting complex network packet capture files.

### Key Topics - **Origins and Requirements**: Developing an open-source, Clojure-based graph database to run in both backend systems and web browsers via ClojureScript, evolving from in-memory pattern matching to a Datomic-style graph database with aggregates. - **Graph Theory and Data Modeling**: Representing entities and relations as directed edges and nodes (statements/triples). Unlike systems that strictly distinguish attributes from edges, Asami maps attributes as edges and values as nodes. - **Triple Indexing and Nested Maps**: Organizing graph statements across three column orderings to enable rapid lookups, pattern rewriting, and joins without full table scans, leveraging Clojure's immutable data structures. - **Durability and Copy-on-Write Trees**: Storing statements as numeric tuples (up to 512 elements per array block) organized in tree indexes (such as AVL trees) using copy-on-write semantics and memory-mapped files. - **Time-Travel and Immutability**: Tracking root node snapshots with timestamps and transaction IDs to support querying historic database states without altering committed data. - **JSON Ingestion and Ad-Hoc Analysis**: Loading raw, untyped JSON directly using string attributes and querying unstructured keys and values using a GraalVM-compiled command-line interface.

### Technical Details - **Compact In-Memory and Durable Encodings**: Values fitting within 60 bits (short strings, keywords, booleans, timestamps, and numbers) are packed into a 64-bit integer, using high-order bits for type tags and lengths. Data exceeding 8 bytes is serialized into buffers referenced by byte offsets and indexed with trees storing the first 16 bytes per node. - **Layered Protocols**: Architecture separated cleanly via Clojure protocols, allowing the block graph to swap underlying implementations (e.g., tuple storage, AVL trees, and memory-mapped block buffers) without altering higher layers. - **Pattern Rewriting vs. Hash Joins**: Asami evaluates query patterns through iterative pattern rewriting and indexed lookups, providing fast join execution. - **Transitive Closures & Optimization**: Implementation of Sparkle-inspired transitive closures uses self-doubling steps (reaching 256 steps in 8 iterations), reducing linear query times from 90 seconds to roughly 80 milliseconds. - **CLI & GraalVM**: Compiled to a native command-line tool, enabling analysts to ingest large files (such as a 7 MB packet capture JSON), index them, and query regex-matched attributes (like query keys containing spaces) within seconds.

### Takeaways Asami offers a lightweight (~7,000 lines of Clojure vs. 100,000 lines of Java in older systems like Mulgara), schema-agnostic solution for loading arbitrary JSON directly into an indexed graph. While bulk indexing large multi-gigabyte datasets requires time, lazy loading and copy-on-write storage deliver sub-second query performance and time-travel querying. It is actively deployed at Cisco in security tooling such as SecureX.

Related talks