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 three hundred years old, and the palace had been patched forty-seven times, and the forty-seven patches were, in the language of the system in Kenji's head, the kind of legacy code that gets a debugger sent to the capital in the first place.

The palace had been built 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. The scrolls were, in Kenji's professional opinion, the worst documentation he had ever read, and he had once been asked to read the documentation for a system that was, in fact, just a series of Post-it notes taped to a wall.

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.

[Audit: palace systems, 47 problems identified]
[Resolved: 30 of 47]
[Remaining: 17, prioritized by mana cost]
[Compiler note: this is the senior engineer who has been asked to onboard a junior palace. The system is, in a small way, paying attention.]

"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 forty percent 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 the southern mine 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.

[Deploy: crystal network, 80 pairs in palace, 30 pairs in city]
[Status: live, stable, mana cost within budget]
[Compiler note: this is a function the developer did not ask for. The system is, in a small way, ahead of the developer.]
[Compiler note: the system approves.]

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 thirty percent more efficiently. The mana cost was down twenty-five percent. 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."

[Compiler note: the developer is, in a small way, ahead of the academy. The system is, in a small way, paying attention.]
[Compiler note: the developer should not get a big head. The system is, in a small way, ahead of the head.]

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."

That evening, Elara found him in the upgraded treasury room, looking at the crystal network's traffic logs. She sat down beside him, the king's father's sword at her hip, and said: "You did a good day's work."

"We did a good six weeks' work."

"We did. The palace is faster. The staff is happier. The king is sleeping. The academy has agreed to teach structured magic. By any reasonable metric, the kingdom is in better shape than it was six weeks ago."

"It is. And that is, in the dry language of the system, exactly when things go wrong."

Elara looked at him. "You think something is going wrong?"

"I think something is going to go wrong. The system has been telling me, for six weeks, that the bug is bigger than the bug reports. The bug is, in the driest possible language, the reason the cult has money, and the reason the nobles were corrupt, and the reason the messenger was killed on the road. The bug is not in the palace. The bug is in the kingdom. The bug is, in the language of the system, the bug that is going to manifest, and the manifesting is going to be visible from the palace, and the visible manifesting is going to be the next thing we have to debug."

Elara did not argue. Elara had learned, in three months of debugging alongside Kenji, that when the system told the developer something, the developer was, in a small way, ahead of the panic, and the panic was, in a small way, the right thing to feel.

Pip orbited the room, slowly, and pulsed once, very softly, and the pulse felt like: "Soon."

Kenji sent back, in the language he and Pip had built together: "I know. I am, in a small way, ready."

The night went on. The palace was upgraded. The crystal network hummed. The system was, in a small way, ahead of the developer, and the developer was, in a small way, ahead of the kingdom, and the kingdom was, in a small way, ready for whatever the system was, in a small way, about to show it.