Project · 03
Distributed Binary Data Sorter
Distributed Computing / Data Processing
Sorts huge lists of numbers across multiple machines, all in binary.
- Year
- 2026
- Stack
- Python · Dispy · struct · threading

Overview
One machine (the coordinator) breaks a big file of numbers into chunks and sends them out to worker machines with Dispy. Each worker sorts its chunk, and the coordinator merges finished chunks two at a time while the rest are still running.
In the final version everything stays in binary — numbers get packed into 4-byte ints before they're sent out and stay that way through every merge, until the very end when it's written out as text.
- Streams the input and packs chunks into 4-byte integers
- Submits each chunk to worker nodes as soon as it's ready
- Workers sort chunks read from shared storage
- Sorted results written back in binary
- Pairwise merging as jobs complete
- Lock-protected merge queue across job callbacks
- Per-job error reporting
- Final merge converts to text output
Focus
- Distributed computing
- Worker nodes
- Binary file I/O
- Synchronization
- Incremental merging
Architecture
The coordinator reads the input as it goes instead of loading it all at once, packs each chunk with Python's struct module, and sends it off right away — so workers start sorting before the whole file has even been read. Every time a job finishes, a callback adds its output to a queue and merges pairs of files, with a lock so callbacks don't step on each other.
Source
- Input dataset
- Chunk + pack to binary
- Dispatch jobs (Dispy)
- Sort on worker nodes
- Incremental binary merge
- Final text output
Evolution
I built this in three steps: get a distributed sort working, figure out where it was doing extra work, test a fix on its own, then put it back in.
01 · Version 1
GitHub — Multinode Data Sorter (opens in a new tab)Multinode Data Sorter
- Split a big text file into chunks on shared storage
- Sent the sorting work out to multiple worker machines
- Merged the sorted files back on the coordinator — but every merge had to read and rewrite each number as text
02 · Experiment
GitHub — Binary Merge Utility (opens in a new tab)Binary Merge Utility
- Merged two sorted files of numbers straight in binary
- Compared the raw 4-byte values instead of reading text lines
03 · Optimized version
GitHub — Binary-Optimized Multinode Data Sorter (opens in a new tab)Binary-Optimized Multinode Data Sorter
- Turn chunks into binary
- Send binary chunks to workers as soon as they're ready
- Sort on the workers
- Merge the binary results as each job finishes
- Write the final result out as text
Performance
I timed three setups on the same million numbers on my laptop. Spreading the work across 14 cores made the pipeline about 5.6× faster than running it in one process — 106 seconds down to 19.
Python's built-in sorted() still beats both at 0.34 seconds. The workers use bubble sort, so the interesting part here is the pipeline, not the sorting algorithm.
Sorting 1,000,000 numbers, three ways
Same 1,000,000 random integers, 160 chunks, all on my MacBook Pro (14 cores) acting as both coordinator and worker. Median of 3 runs (the one-process run ran once). Every output was checked: sorted, nothing missing.
Distributed times start once the cluster is up.
What I learned
The big thing I learned is that making something faster isn't only about a better algorithm. A lot of it is about where the work happens. Splitting the job across machines, letting workers start sorting while the coordinator is still reading the file, and merging results as they come in all cut down on time spent waiting.
Same idea between systems: keeping the data in binary as it moves between the coordinator and the workers, instead of converting it back and forth, saved work at every step.
Repositories
- bin-opt-multinode-data-sorter-py (opens in a new tab)Final version — binary chunks, sorting across machines, merging as results come in.
- multinode-data-sorter (opens in a new tab)Version 1 — text chunks sorted across machines and merged on the coordinator.
- binary-merge-py (opens in a new tab)Side experiment — merging sorted number files straight in binary.
Stack
- Python
- Dispy
- struct
- threading
Contact
Get in touch.
Want to talk about something I've built, or something you're building? Email's the fastest way to reach me.