Skip to content

Remove the support for event, command and snapshot JSON in text columns - #559

Merged
erikrozendaal merged 2 commits into
masterfrom
improvement/remove-text-json-columns
Nov 4, 2026
Merged

erikrozendaal merged 2 commits into
masterfrom
improvement/remove-text-json-columns

Conversation

@erikrozendaal

Copy link
Copy Markdown
Member

Since Sequent 8 the event store keeps the JSON of events, commands and snapshots in jsonb columns of its own schema, so the support for JSON in text columns is dead code that still costs something: every loaded event was assigned to a new event_record_class instance just to be deserialized. Removing it simplifies the records and makes loading events about 40% faster.

Measured with an event of 10 attributes (including a value object and arrays): deserialize_event went from 24 to 14 µs and from 179 to 141 allocations per event, and load_events of 2,000 events from 30 to 19 µs per event. This is a breaking change for applications with their own record classes relying on serialize_json? or serialize_to_json, described in the changelog.

Since Sequent 8 the event store keeps the JSON of events, commands and
snapshots in jsonb columns, and the event_records and command_records
views are part of Sequent's schema, so the branches for JSON in a text
column were no longer used. The event store now deserializes loaded
events directly from their JSON, instead of assigning it to a new
event_record_class instance first.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Accessor-backed event and command records retain raw Time values instead of JSON-normalized strings, causing subsequent deserialization to fail.

1 open issue
What changed in this PR

This PR removes legacy text-column JSON support now that Sequent’s event store uses jsonb, simplifying record serialization and speeding up event loading.

Changes:

  • Remove text-column serialization helpers from event, command, and snapshot records.
  • Deserialize loaded events directly without creating intermediate record instances.
  • Update serialization specs and document the breaking changes.
File Description
spec/​lib/​sequent/​core/​serializes_event_spec.rb Expect event payloads as hashes.
spec/​lib/​sequent/​core/​serializes_command_spec.rb Expect hashes and remove legacy serialization overrides.
lib/​sequent/​core/​snapshot_record.rb Remove snapshot column-type detection.
lib/​sequent/​core/​event_store.rb Deserialize events without intermediate records.
lib/​sequent/​core/​event_record.rb Remove text-JSON conversion and serialization helpers.
lib/​sequent/​core/​command_record.rb Remove text-JSON conversion and column-type detection.
CHANGELOG.md Document compatibility changes and loading performance gains.

Review effort: Balanced

Comment thread lib/sequent/core/event_record.rb Resolved
A record that includes SerializesEvent or SerializesCommand without
being an ActiveRecord model with a json column, like one using
attr_accessor, kept the Time values of the attributes, and could not
load the event or command again. as_json gives the values they are
loaded from; ActiveRecord's json type casts them the same way.
@erikrozendaal
erikrozendaal merged commit 7aaf79d into master Nov 4, 2026
8 checks passed
@erikrozendaal
erikrozendaal deleted the improvement/remove-text-json-columns branch November 4, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants