Season 3 Episode 8

The Palace Upgrades

Key scene illustration
Key scene illustration

In which our protagonist refactors a palace, and Master Yuen arrives in person.


The palace was, like most of the kingdom, legacy code.

It had been built three hundred years ago, in the style of the time, which meant that the plumbing was magic, the lighting was mana, the security was a mix of physical and magical, and the documentation was a series of scrolls in a vault that no one had opened in a hundred years.

Kenji spent the first week just walking the palace, mapping the systems, identifying the bottlenecks. He had Pip orbit his head and Lian at his side with her notebook, and they wrote down everything: which spells were running, which were degraded, which were failing silently, which were drawing more mana than they should.

By the end of the week, he had a list of forty-seven problems. By the end of the month, he had fixed thirty of them.

The fixes were not dramatic. They were the kind of fixes that a competent system administrator would do in any large organization: tightening permissions, optimizing queries, replacing deprecated functions, removing dead code. The palace was not broken. It was just old, and slow, and held together by the kind of patches that accumulate over centuries.

"The original architect was brilliant," Kenji said, to Lian, on the morning of day twenty. "But the architecture was for a smaller palace. The current palace is three times the size. The systems have been scaled up, but not refactored. We are paying a 40% mana tax for the privilege of running on legacy code."

"Can we refactor it?"

"We can refactor some of it. We cannot refactor all of it. The risk of a full refactor is too high. We do it incrementally. We identify the worst-performing systems. We rewrite them. We deploy. We monitor. We move to the next one."

"Like Sprints."

"Exactly like Sprints. We are doing DevOps for a palace."

Lian did not know what DevOps was. She nodded anyway. She had learned, in three months of apprenticeship, that Kenji's metaphors were often more useful than his explanations.

The palace upgrades continued for six weeks. Kenji and Lian, working together, replaced the lighting system, the heating system, the security system, the water system, and the messaging system. The messaging system was the most important: it was the palace's internal communication network, and it was slow, unreliable, and dependent on a single courier who was, the palace staff said, "very loyal but very old."

Kenji replaced it with a crystal network.

The crystal network was a system of enchanted crystals, each one paired with another, that could send messages instantly across any distance. It was, in the language of his old job, an instant messaging system. It was, in the language of magic, a spell that Kenji had invented in S2E9 and refined in the six weeks since.

The crystals were small, the size of a thumbnail, and they came in pairs. You wrote a message on one crystal, and it appeared on the paired crystal, instantly, regardless of distance. The mana cost was low. The range was unlimited. The only limitation was that you had to have a paired crystal, which meant the network was closed. You could only talk to people you had been paired with.

It was, Kenji realized as he deployed it, the perfect system for a kingdom that did not trust its own nobles.

By the end of the six weeks, the palace was running 30% more efficiently. The mana cost was down 25%. The staff was happier. The king was sleeping better. The kingdom was, for the first time in a long time, being run like a system that had been designed, rather than a system that had been patched.

Then Master Yuen arrived.

The master mage walked into the palace, looked at the upgraded systems, looked at the crystal network, looked at Kenji, and said: "I have been teaching magic for forty years. I have never seen anything like this."

"I have been debugging systems for ten years. The principle is the same."

"It is not the same. Magic is not a system. Magic is an art."

"Magic is a system. The academy just does not know it yet."

Master Yuen looked at him for a long moment. Then she said: "I am here to invite you to the academy. As a guest lecturer. The king has approved it. You will teach structured magic to the senior students, twice a week, on Tuesdays and Thursdays."

"Tuesdays and Thursdays," Kenji repeated. "I have Sundays off."

"Sundays are yours. Tuesdays and Thursdays are the academy's."

"Done."

Master Yuen nodded. Then she said, quietly: "I was wrong about you. I thought you were a fraud. A foreigner with strange magic and a strange dragonfly. I was wrong. You are the most important mage in the kingdom. Possibly the most important mage in the world."

"I am just a debugger."

"You are a debugger who debugs magic. That is unprecedented. That is, in fact, the most important kind of mage there is."

She left. Kenji watched her go, and Pip pulsed, amused. The pulse felt like: "Important."

Kenji sent back: "Maybe. But I still have Sundays off."

# WORLD.md (updated)

## Status
- Palace: 30% more efficient, 25% mana cost reduction
- Crystal network: deployed, instant messaging across the kingdom
- Master Yuen: arrived, formally invited Kenji to lecture at the academy
- Academy: Tuesdays and Thursdays, structured magic curriculum

## Lessons
- Legacy code can be refactored incrementally
- A crystal network is an instant messaging system, and instant messaging is political power
- A 30% efficiency gain is worth a hundred speeches
- "I have Sundays off" is the hill, again