Saturday, May 14, 2011

Dual Dishwashers and Active/Inactive Database Tables

If you have a small kitchen like mine, you can't have 2 dishwashers. But I dream to have dual dishwashers. Why? The most obvious is capacity. After entertaining a crowd of friends, you will need the dirty dishes to be cleaned quickly. However, if it's just for more room, there are roomier washers that can fit more plates.

I would claim that the best benefit of having 2 dishwashers at a single home is the convenience.

How many times are you tired of unloading your completed wash, while your soiled plates are waiting in the kitchen sink?

With 2 dishwashers, you practically don't need to unload any more. Washer 1 contains clean plates where you directly take plates out of at dinner time, and washer 2 is where you stuff dishes into after dinner. When washer 2 is full, or, washer 1 is empty, simply kick off a wash cycle. Then, viola! Magically, washer 2 becomes your clean repository, and washer 1 is waiting for dirty ones.

Will it be confusing to home owners which one is the clean one? Yes, but, it's easy to solve, isn't it? Ever seen these kitchen magnets that have labels "Clean" or "Dirty" on them? As soon as you kick off a wash cycle, place "Clean" on it.

Now, as I promised, I'll show you how this concept is used in software engineering.

There are often needs to populate a database table with data coming from SAS reports, or business units, or external vendors. If you truncate the table and load the data, the production use cases will be interrupted (because once the table is emptied, applications read from the empty table).

The solve is quite simple - you need 2 dishwashers, urgh, I mean, 2 tables. Mark table 1 active and table 2 inactive. Production reads from table 1 (active). When the updated data file is ready, truncate the inactive table 2, load the data in. Then, switch active table to table 2, and mark table 1 as inactive. Now, production starts to read from table 2, and table 1 can be emptied any time. No downtime is required.

Hint: Clean/Dirty magnets don't help in the software example. Instead, you will need a global flag in database or application to indicate which table is active.

No comments:

Post a Comment