Design Patterns Inside Ultrasound Machines
Design patterns are often taught using academic abstractions: shapes, payment gateways, or coffee shop decorators. But when I began working on ultrasound medical systems, I wasn’t thinking about “Gang of Four” diagrams. I was thinking about frame rates, safety regulations, and hardware constraints.
Over time, I realized something: In medical software, design patterns aren’t about elegance — they’re about survival. In a system where a software crash isn’t just a bug but a clinical delay, these patterns emerge naturally because any other architecture eventually collapses.
Here is how they manifest in the real world.
1. The Strategy Pattern: Imaging Modes
Ultrasound machines aren’t just one device; they are a dozen devices in one. You have B-Mode (the classic grayscale), Doppler (blood flow), and M-Mode (motion tracking).
Each mode requires a completely different processing pipeline and rendering logic. We use the Strategy Pattern not because we want “pluggable code,” but to isolate risk.
- The Reality: Mixing Doppler logic with B-Mode logic creates a “spaghetti” mess that makes FDA Validation (the formal process of proving software is safe for intended use) a nightmare. By isolating them into discrete strategies, we ensure that a change in how we calculate blood flow velocity doesn’t accidentally break the basic imaging path.
2. The State Pattern: Contextual Logic
A button press on an ultrasound console means nothing without context.
- If the system is in a Freeze State, the “Save” button stores a static image.
- In an Acquisition State, it might start a cine-loop recording.
- In a Measurement State, it might set a caliper point.
Instead of a 2,000-line switch statement, the State Pattern allows the system to swap its entire personality. This reduces “illegal state transitions” — preventing the system from trying to fire a high-voltage pulse while the user is just reviewing a saved file.
3. The Observer Pattern: Decoupling the Frame Stream
When a new frame comes off the hardware, everyone wants a piece of it.
- The Display needs to render it.
- The Measurement Engine needs to track a fetal heart rate.
- An AI Module might be scanning for anomalies.
Using an Observer Pattern is critical for system stability. If the “AI Module” hangs for 20ms, it shouldn’t “block” the UI thread. The system broadcasts the frame and moves on. In medical devices, the image must always flow; everything else is secondary.
4. The Facade & Adapter: Taming the Metal
Ultrasound software lives on top of terrifyingly complex hardware — probes with hundreds of elements, high-voltage beamformers, and specialized FPGAs.
- The Facade: We use this to hide the hardware’s complexity. The application-level code asks for “Start Stream,” and the Facade handles the hundreds of registers that need to be flipped in the background.
- The Adapter: This is our best friend for AI integration. AI models change every six months; our core architecture lasts a decade. We wrap third-party inference engines in Adapters so that when we switch from a local model to a cloud-based API, the rest of the system remains stable.
5. The Command Pattern: User Intent as Data
When a sonographer turns a Gain knob (the “volume control” for image brightness) rapidly, they generate a stream of intents.
Get Arnab Das’s stories in your inbox
Join Medium for free to get updates from this writer.
By encapsulating these as Commands, we can:
- Queue them if the processor is busy.
- Coalesce them (if five gain changes happen in 10ms, only the last one matters).
- Treat user input as an intent to be managed, rather than a function to be executed immediately. This is vital in real-time systems where timing is everything.
The Singleton Pattern: Hardware Authority
In a medical device, you aren’t just managing data; you are managing physical, high-voltage hardware. There is only one beamformer board and one transducer connector. If two different modules tried to send conflicting instructions to the hardware simultaneously, it could lead to system instability or hardware damage.
The Reality: We use the Singleton pattern to create a single “Source of Truth” for the hardware interface. By ensuring only one instance of the Hardware Controller exists, we prevent “resource contention” — the digital equivalent of two people trying to steer a car in different directions. In a regulated environment, the Singleton provides a guaranteed, centralized point for safety logging and error handling, making it much easier to prove to auditors that the hardware is being accessed safely.
The Flyweight Pattern: Memory Preservation
Ultrasound generates a massive stream of high-resolution data — often 60+ frames per second. If you have multiple UI components (a main view, a thumbnail gallery, and an AI analysis window) all trying to hold that data, the system will run out of memory and crash.
The Reality: We use the Flyweight pattern to share the “heavy” raw pixel data across the entire application while keeping the “light” metadata (like zoom levels or brightness settings) separate for each view. In a clinical setting, a memory leak or an “Out of Memory” error isn’t just a nuisance; it’s a system failure during a critical diagnostic moment. Flyweight ensures the image stays in RAM without duplicating the footprint.
Why Patterns Aren’t Optional in Regulated Med-Tech
In most industries, design patterns improve code quality. In medical systems, they provide Safety and Longevity.
- Validation: It is much easier to prove to a regulator that a specific “Strategy” is safe than to prove a monolithic block of code is safe.
- Evolution: Hardware evolves faster than software. Patterns like Facades and Adapters allow us to swap out a $5,000 transducer without rewriting the entire UI.
Final Thought
Working on these systems changed my perspective. I still don’t care much for coffee shop decorators, but I’ve learned to love the Strategy Pattern. Not because it makes the code elegant, but because it ensures that when a doctor needs to see blood flow in a flickering heart, the system delivers — every single time.
Also, Design patterns aren’t academic tools to be used for “cleanliness.” They are the structural beams that keep a complex, high-stakes system from buckling under its own weight. In medical software, good design isn’t a luxury. It’s a Clinical Requirement.
Appendix: A Mini-Glossary
- B-Mode: The “default” 2D grayscale ultrasound view.
- Doppler Mode: Used to visualize blood flow velocity and direction.
- Gain: Electronic amplification of returning signals (brightness control).
- TGC (Time Gain Compensation): Specific gain adjustments for different depths.
- Cine-loop: A short, continuous loop of ultrasound frames (like a medical GIF).
- FDA Validation: The formal requirement to provide objective evidence that the software meets user needs and safety standards.









