Go-live day for the new CabinetWorld redesign was a tense, hurried affair. Developers streamed in at 5:00 AM, hoping to catch wind of early problems before most of the country awoke and started shopping. True to form, the overworked break-room coffee machine gave up the ghost at 5:10, but luckily, at 6:00 the boss brought in doughnuts, and by 6:30 a Starbucks run had been arranged. Everyone huddled in the war room, nervously watching the monitors as the number of concurrent visitors rose steadily. And then ...

1890s Burroughs adding machine

"Why's it slowing?" Ashley whispered, not wanting to cause a panic.

Dave stuffed the rest of a cruller into his mouth and looked where she was pointing: one particular API service was buckling under the so-far moderate load. Oddly enough, this wasn't part of the overhaul. This service, which merely returned a product list, was a legacy service they'd switched to using, one that powered their own internal tools. It should've been nice and stable—but instead, it chugged along like it had eaten a few too many doughnuts itself.

Dave grabbed the source code while Ashley combed the production logs, looking for the source of the slowdown. "Crap," whispered Dave, noticing the version control history. "That's Bruce the Intern's work."

Bruce had been the "clever" intern the summer he'd worked at CabinetWorld, the one they'd assigned actual coding tasks to. Unfortunately, he'd been too clever for his own good, as the code revealed:


public List getAllCabinets() {
	try {
		List m = new Vector();
		List cabinets = SpecificObjectManager.getAllPrograms();
		Iterator it = cabinets.iterator();
		while (it.hasNext()) {
			CabinetAjax ca = new CabinetAjax();
			SearchProgramShell cabinet = (SearchProgramShell) it.next();
			ca.setId(cabinet.getCabinetId());
			ca.setTitle(cabinet.getCabinetTitle());
			Collections.sort(m, new CabinetAjaxTitleComparator());
			m.add(ca);
		}
		return m;
	} catch (Exception e) {
		log.error(e.toString(), e);
	} finally {
		HibernateSessionFactory.closeSession();
	}
	return null;
}

"That is, without a doubt, the worst sort I've ever seen," whispered Ashley, paling. "Why does it re-sort every iteration?"

"It doesn't even work. The last element won't be sorted," Dave whispered back.

"Why a vector of CabinetAjaxes? Why not just a Map, ID to title?"

"God only knows."

"What do we do now?" Ashley glanced up at the increasingly red monitors. "Do we roll back?"

Dave clamped a hand over her mouth. "Not so loud! No. We write a patch and fail forward, of course." He rapidly moved the sort code to just before the return, saved, and committed. "Let's see if we can bribe Ops with some of these donuts ..."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!