Bolt (network protocol)

{{Use mdy dates|date=June 2017}}

{{Infobox software

| name = Bolt

| author = Neo4j

| genre = Network protocol

| license = Creative Commons 3.0 Attribution-ShareAlike

| programming language = Various languages

| operating_system = Any

| platform = Cross-platform

| latest_release_version = Version 5.8

| website = {{URL|https://www.neo4j.com/docs/bolt/current/}}

}}

The Bolt Protocol (Bolt) is a connection oriented network protocol used for client-server communication in database applications. It operates over a TCP connection or WebSocket.

Bolt is statement-oriented, allowing a client to send messages containing a statement consisting of a single string and a set of typed parameters. The server responds to each statement with a result message and an optional stream of result records.

History

The Bolt protocol was first introduced to the public in November 2015, during an interview conducted by Duncan Brown and published on [https://dzone.com/pages/about DZone].{{cite web|url=https://dzone.com/articles/introducing-bolt-neo4js-upcoming-binary-protocol-p|title=Introducing Bolt, Neo4j's Upcoming Binary Protocol – Part 1 - DZone Database|website=dzone.com|accessdate=June 2, 2017}} The first release of software implementing the protocol occurred in December 2015, as part of a milestone release of Neo4j Server.{{cite web|url=https://neo4j.com/blog/neo4j-3-0-milestone-1-release/|title=Bolting Forward: The Neo4j 3.0 Milestone 1 Release Is Here - Neo4j Graph Database|date=December 4, 2015|website=neo4j.com|accessdate=June 2, 2017}} In April 2016, Neo4j Server 3.0 was released and contained the first server implementation of the protocol, accompanied by a suite of Bolt client drivers. This release received attention from several mainstream media outlets.{{cite web|url=https://www.theregister.co.uk/2016/04/26/neo4j_bolts_on_binary_protocol_to_up_graph_database_game/|title=Neo4j bolts on binary protocol to up its graph database game|date=26 April 2016|first=Alexander J.|last=Martin|website=theregister.co.uk|accessdate=June 2, 2017}}{{cite web|url=https://www.infoq.com/news/2016/04/neo4j-3.0|title=Neo4j 3.0 Released with Binary Communication Protocol and Standardised Drivers|website=InfoQ|accessdate=June 2, 2017}}{{cite web|url=http://www.tomsitpro.com/articles/neo-technology-releases-neo4j-3,1-3253.html|title=Neo Technology Releases Neo4j 3.0|date=April 26, 2016|website=tomsitpro.com|accessdate=June 2, 2017|archive-url=https://web.archive.org/web/20170507093238/http://www.tomsitpro.com/articles/neo-technology-releases-neo4j-3,1-3253.html|archive-date=May 7, 2017|url-status=dead}}

Versioning

The Bolt network protocol uses version negotiation to ensure compatibility between clients and servers. Clients send up to four supported protocol versions, encoded as 32-bit integers, prioritizing earlier entries. The server responds with the highest compatible version or a zero value if no match is found, closing the connection. Starting with Bolt 4.0, the protocol supports major and minor versioning. Bolt 4.3 introduced range-based minor versioning, allowing clients to specify consecutive minor versions compactly.{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/handshake/#_version_negotiation|title=Versioning|website=neo4j.com|accessdate=January 10, 2025}}

Protocol overview

Protocol new versions are released regularly, introducing enhancements in performance, functionality, and compatibility.

=Messaging=

File:Bolt-typical-interaction.png

Bolt clients and servers both send data over the connection as a sequence of messages. Each message has a type (denoted by a "signature" byte) and may include additional data. The client drives the interaction, and each message sent by the client will cause one or more response messages to be sent by the server.

The following information pertains to Bolt version 5.8 and may not reflect the latest developments in the protocol.

Client messages:

class="wikitable"
TypeSignature
HELLO0x01{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-hello|title=Hello message|website=neo4j.com|accessdate=January 9, 2025}}
LOGON0x6A{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-logon|title=Logon message|website=neo4j.com|accessdate=January 9, 2025}}
LOGOFF0x6B{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-logoff|title=Logoff message|website=neo4j.com|accessdate=January 9, 2025}}
TELEMETRY0x54{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-telemetry|title=Telemetry message|website=neo4j.com|accessdate=January 9, 2025}}
GOODBYE0x02{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-goodbye|title=Goodbye message|website=neo4j.com|accessdate=January 9, 2025}}
RESET0x0F{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-reset|title=Reset message|website=neo4j.com|accessdate=January 9, 2025}}
RUN0x10{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-run|title=Run message|website=neo4j.com|accessdate=January 9, 2025}}
DISCARD0x2F{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-discard|title=Discard message|website=neo4j.com|accessdate=January 9, 2025}}
PULL0x3F{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-pull|title=Pull message|website=neo4j.com|accessdate=January 9, 2025}}
BEGIN0x11{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-begin|title=Begin message|website=neo4j.com|accessdate=January 9, 2025}}
COMMIT0x12{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-commit|title=Commit message|website=neo4j.com|accessdate=January 9, 2025}}
ROLLBACK0x13{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-rollback|title=Rollback message|website=neo4j.com|accessdate=January 9, 2025}}
ROUTE0x66{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-route|title=Route message|website=neo4j.com|accessdate=January 9, 2025}}

Server messages:

class="wikitable"
TypeSignature
SUCCESS0x70{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-success|title=Success message|website=neo4j.com|accessdate=January 9, 2025}}
FAILURE0x7F{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-failure|title=Failure message|website=neo4j.com|accessdate=January 9, 2025}}
IGNORED0x7E{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-ignored|title=Ignored message|website=neo4j.com|accessdate=January 9, 2025}}
RECORD0x71{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#messages-record|title=Record message|website=neo4j.com|accessdate=January 9, 2025}}

=Message transfer encoding=

Each message is encoded into a sequence of bytes. These bytes are transferred using a binary chunked encoding, where each chunk is preceded by an unsigned, big-endian 16-bit integer denoting the number of bytes that immediately follow. A length of 0 is used to denote the end of the message.

=Failure handling=

A client may send multiple messages to a server, without first waiting for a response.{{cite web|url=https://www.neo4j.com/docs/bolt/current/bolt/message/#pipelining|title=Pipelining|website=neo4j.com|accessdate=January 9, 2025}} The server processes each message sequentially. However, as there may be logical dependencies between messages sent by the client, the server will not evaluate requests it receives after sending FAILURE in response to a preceding message. Instead, it will send an IGNORED message in reply to every client message, until the client acknowledges the failure by sending an RESET message.

This is similar to the failure handling and recovery in the PostgreSQL wire protocol.

PackStream overview - version 1

PackStream is a binary presentation format for the exchange of richly-typed data. It provides a syntax layer for the Bolt messaging protocol.

=Data encoding=

Bolt supports encoding for a number of different data types.

class="wikitable"
TypeDescription
Null{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-null|title=Null data type|website=neo4j.com|accessdate=January 10, 2025}}Represents the absence of a value.
Boolean{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-boolean|title=Boolean data type|website=neo4j.com|accessdate=January 10, 2025}}Boolean true or false.
Integer{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-integer|title=Integer data type|website=neo4j.com|accessdate=January 10, 2025}}64-bit signed integer.
Float{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-float|title=Float data type|website=neo4j.com|accessdate=January 10, 2025}}64-bit floating point number.
Bytes{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-bytes|title=Bytes data type|website=neo4j.com|accessdate=January 10, 2025}}Byte array.
String{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-string|title=String data type|website=neo4j.com|accessdate=January 10, 2025}}UTF-8 encoded string.
List{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-list|title=List data type|website=neo4j.com|accessdate=January 10, 2025}}Ordered collection of values.
Dictionary{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-dictionary|title=Dictionary data type|website=neo4j.com|accessdate=January 10, 2025}}Collection of key-value entries (no order guaranteed).
Structure{{cite web|url=https://www.neo4j.com/docs/bolt/current/packstream/#data-type-structure|title=Structure data type|website=neo4j.com|accessdate=January 10, 2025}}Composite value with a type signature.

References

{{reflist|30em}}