r/AskProgramming • u/ImportantPudding1570 • Oct 25 '26
Is this considered duplicate code?
How do you decide when code duplication across different markets is actually worth eliminating?
I'm building a framework to automate complex business logic for incoming customer support emails. The system is currently being implemented for England, but it will eventually expand to Germany, the USA, India, and other markets.
The challenge is that many business rules are shared across markets, while others are market-specific.
For example:
- Germany and the USA require checking whether a customer has logged in within the last 30 days.
- England and India don't require this check.
- Other parts of the email-processing workflow may be common across all markets, while some may differ.
My initial approach was to create a common interface with separate implementations for each market:
However, I'm concerned that this could lead to significant code duplication as the framework grows.
On the other hand, suppose Germany and England currently have 100 lines of identical logic. Even if the logic is identical today, the business requirements for those countries may evolve independently. Sharing the implementation could introduce unintended coupling, where a change intended for one market affects another.
I am offcourse planning on building common "Helpers" and whatever can be configurable, will be configurable. However, we currently will only be getting requirements for one market, we can not tell from start if something that we will use, will be reused by other markets.
My question is: How do you approach this trade-off in practice?
- If I go with the initial approach, will these same line of code will actually be considered as a duplicate and will break the DRY principle?
- If Yes, would you consider identical code across markets to be duplication worth eliminating, even when the underlying business rules may evolve independently?
- Would you build a shared processing engine with market-specific configuration or strategies, or maintain separate implementations for each market?
- How do you decide which logic to abstract and share versus which logic to keep separate to preserve independence between markets?
I'm particularly interested in the reasoning behind these decisions and any real-world experience building systems with complex, evolving market-specific business rules.
View all comments
5
u/rupertavery64 Oct 25 '26 edited Oct 25 '26
It seems like what you need is a rule engine.
That way you can keep related code in one place, and apply it generally to the pipeline. Then perhaps have a method to check if the rule applies, and another to apply the rule.
Then have a list of rules and apply then to the email.
It makes it easy to add rules, whilst keeping the knowledge about the rule close together, rather than spread out across several files.
You can implement different rules across different markets.
And the neat thing about this is since the rules are separate you can manage them programmatically. i.e. you can configure rulesets through a UI instead of hardcoding them.