From Serializer to JsonStreamer: the debrief

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

From Serializer to JsonStreamer: the debrief

Reindexing millions of documents across 10 Elasticsearch indexes was taking hours, long enough that it only ran on weekends. With a growing number of custom Normalizers slowing things down, Symfony's Serializer wasn't cutting it anymore.

We built a proof of concept with Symfony's JsonStreamer to see if it was as fast as advertised.

This talk is an honest account of that journey: the challenges, what we learned, and how it could apply to your application as well.

Delivered in English

Gary PEGEOT

November 30, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

25 slides
  1. From Serializer to JsonStreamer: the debrief How BSN Sports cut

    its Elasticsearch indexing time tenfold @GaryPEGEOT . Argo
  2. 01 · The context What is BSN Sports? #1 150,000+

    provider of team sports uniforms, apparel and equipment in the US customers: schools, colleges, clubs and recreational programs Varsity Brands part of the group, headquartered in Texas
  3. 02 · The tech stack A pretty common stack 

      API Platform MySQL Elasticsearch The API layer, on top of Symfony The main database With elastically for index creation and hydration
  4. 03 · Performance issues It worked fine… until it didn’t

    Worked fine at first, but performance became an issue Full indexing only on weekends 10 indexes, about 46 million documents
  5. 04 · The current process The problem with the current

    process STEP 1 STEP 2 STEP 3 · TOO LATE Create the index Mark it as “live” Only then, fill it The index goes live before it holds any data.
  6. 05 · The bottleneck Where the time goes Many Limits

    custom normalizers the Serializer starts to show them
  7. 06 · Solutions considered In the BC era (Before Claude)

    Profiling amphp/parallel Caching …
  8. 07 · A (very) new hope JsonStreamer A new Symfony

    component, about to be released Part of the Symfony ecosystem Claims a 10× performance boost 10× claimed speed-up
  9. 08 · The catch The problem with “experimental”  

     The API may change No official support from third parties Sparse documentation
  10. 09 · Let’s make a POC POC architecture  

     A dedicated command HttpClient JsonStreamer or Serializer for indexing sends the bulk requests to Elasticsearch depending on support and a feature flag
  11. 09 · Let’s make a POC An unfortunate format Elasticsearch’s

    Bulk API speaks NDJSON (newline-delimited JSON) POST /_bulk One object per line Content-Type: application/x-ndjson An action line, then its document { "index": { "_index": "design", "_id": "1" } } { "name": "Home jersey", "sport": "basketball" } { "index": { "_index": "design", "_id": "2" } } { "name": "Away jersey", "sport": "soccer" } ↵ final newline required Not one JSON document A JSON writer can’t produce the whole body in one go
  12. 09 · Let’s make a POC A change of paradigm

    STEP 1 STEP 2 STEP 3 · ONLY WHEN DONE Create a new index Fill it Mark it as “live” once the full indexing is finished
  13. What we have Symfony Serializer #[ORM\Entity] class Product { #[ORM\Id,

    ORM\GeneratedValue, ORM\Column] #[Groups(['product:read', 'search'])] private int $id; #[ORM\Column(length: 255)] #[Groups(['product:read', 'search'])] private string $name; // ... } Pros Simple & well known One class, ∞ possibilities Very customizable Cons Slow One class, ∞ representations Promotes larger-than-necessary responses
  14. What we need JsonStreamer by Mathias Arlaud, from Baksla.sh final

    class ProductDocument { public int $id; public string $name; } $type = Type::list(Type::object(ProductDocument::class)); $json = $jsonWriter->write($documents, $type); Pro Fast AF Pro One class → one representation
  15. What we need · JsonStreamer The trade-offs Cons JSON only

    No groups Needs many new DTOs (BC era) No getters / setters, no constructors (JSON → DTO only), everything public DTOs need to be hydrated beforehand
  16. What we need ObjectMapper by Antoine Bluchet (aka soyuka) A

    ObjectMapper Bridges the functionality gap Moves data from A to B B Allows data customization and transformation
  17. What we need · ObjectMapper Mapping an entity to a

    DTO #[Map(target: CatDocument::class)] class Cat { #[Map(target: 'displayName')] public string $name; target Renames a property in the DTO transform #[Map(transform: 'strtoupper')] public string $color; #[Map(if: false)] public string $internalNotes; } // Entity → DTO, ready for JsonStreamer $doc = $objectMapper->map($cat); Changes the value on the way if Leaves a property out
  18. First results Indexing time, divided by 10 26 min →

    3 min to reach 28% of the “design” index (210,080 documents) Without JsonStreamer vs. with JsonStreamer
  19. A bumpy road Indexing is 10× faster, but it took

    many adjustments to get there.
  20. A bumpy road With JsonStreamer Error messages were… cryptic Beware

    of array PHPDoc: That’s it. Foo[] vs list<Foo>
  21. A bumpy road With ObjectMapper CPP to catch errors immediately

    Constructor property promotion: we don’t use JSON decoding Trial and error Few transformers to figure out the mapping direction Early on, transformers like MapCollection were missing
  22. Quality The testing problem Test coverage is quite decent, but:

    Mostly “surface tests” We don’t test every property returned by the API. The API produces the data but doesn’t consume it A React front end does, and its test coverage is minimal.
  23. The POC results From POC to production 2026 0 10×

    went into production this year outages shorter indexing time

Other Decks in Programming