The function began with a modest responsibility. Then it learned about approval limits, supplier availability, notifications and what to do when a request times out.
Now it is effectively operations manager, working without a chair.
If you recognize that shape in an application, the answer isn’t automatically to split it into twenty smaller functions. That may improve readability while leaving the difficult recovery problem exactly where it was.
The real choice is whether the work is one local operation or a business process that can continue, wait and fail across several boundaries.
When smaller functions may be enough
A long method can simply contain too many ordinary calculations or checks. Clearer names, focused functions and better boundaries may make it easier to understand and test.
Don’t buy a workflow engine because a line count looks unfriendly. A straightforward operation shouldn’t acquire a message broker merely to improve its posture.
The more important questions concern time and side effects. Does it call an external provider? Does a later step depend on a response that might arrive much later? Can part of the work succeed before another part fails?
Derek Comartin’s June 2024 workflow discussion highlights that distinction.2 Rearranging code doesn’t create a distributed transaction or make a remote side effect reversible.
When the process needs explicit states
Imagine a fictional equipment request that moves through these stages:
- Record the request and the details staff must review.
- Obtain an approval where the rules require one.
- Ask the supplier to confirm availability.
- Record the resulting commitment or exception.
- Notify the customer of the actual outcome.
That is an outline for discussion, not a universal sequence. The business should decide what each state means and who may move it forward.
Connecting systems that were never introduced? See our integrations and AI work.
Record the next step reliably
Suppose approval is saved locally and a notification to another component must follow. If the application fails between those actions, the process can stop despite the approval existing.
An outbox pattern can store the intended outgoing message in the same database transaction as the local change. A separate process then attempts publication.
Milan Jovanovic’s outbox explanation shows how that closes the gap between committing data and remembering to send the message.3 It still requires handling retries and duplicates; it isn’t a guarantee that every external effect occurs exactly once.
The benefit is a durable record of work to continue, rather than hoping the application gets through several unrelated operations before anything interrupts it.
Decide what recovery means at each boundary
If the supplier cannot fulfill the request, the system may need staff review or another supplier. It should not silently restart the whole customer journey.
Comartin’s orchestration work describes coordinating a longer process through explicit steps and responses. A workflow framework may provide useful persistence, retries and timeout handling.
Choose it based on the process and the team’s operating needs. The tooling supports the agreement; it doesn’t decide whether the business should cancel, wait or compensate for an earlier action.
Compensation is also new work. Sending a cancellation request doesn’t erase the original booking, and a refund doesn’t remove every trace of the payment. Record what actually happened.
If this was useful, try When the automation diagram starts needing its own map.
Give support something better than an exception message
A person investigating the fictional request should be able to see its current state, completed actions and the reason it is waiting. They shouldn’t have to infer the business process from the order in which log files become interesting.
Test an interruption around each important boundary. Can the work resume safely? Does a repeated message create another commitment? Can a human resolve an exception without guessing which steps to repeat?
I would refactor around those answers, keeping the implementation as simple as the process allows.
The result may still involve several functions. The difference is that they now participate in an understandable workflow instead of living inside one enormous try-catch arrangement.
Our overpromoted function can return to a reasonable job. Everybody benefits when the operations manager stops being a method.