Design decides on performance

In our legacy system, we found a stupid design decision. We provide the service of business suite for our customer.  The relationship between customer and business suite is stored in the user_busi_suite table. When the administrator of system want to delete the specific business suite, the program should check whether the business suite was subscribed by user at first.  If the business suite had been subscribed, it will popup the alert window to give the noticement.

Guess how to implement this function in the legacy system? It fetched the all user who subscribed this suite, then draw a dicision whether delete it depending on the size of user list:

List<User> users = busiSuiteRepository.fetchSubsribersWith(suiteId);
if (users == null || users.size() == 0) {    

Its implementation will effect on the performance seriously. The query of the user with suite is not necessary. We should better define the property for BusinessSuite which indicates whether it was subscribed by user. Like this:

public class BusinessSuite {    
    private boolean subscriptionFlag = false;    
    public boolean isSubscribed() {        
        return subscriptionFlag;    
    public void subscribe() {        
        subscriptionFlag = true;    

BusinessSuite bs = busiSuiteRepository.with(suiteId);
if (!bs.isSubscribed()) {    

Don’t need to query the list of user, we only get the value of subsription flag to draw a decision. That’s easy!


Author: Bruce Zhang

I am software developer in BigEye Data as cofounder. I mainly focused on big data, software architecture. I expert in Java, Scala, .NET, Javascript developing. Now I am interesting in elixir language which is based on Erlang virtual machine.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s