AWS Builder Center

The Night Watch

Aetherspire Chronicles, Part 1: AWS Lambda. A city in the skies, two friends who keep it running, and why the girl who watches the beacon shouldn't spend 72 hours a week awake for six minutes of real work.

The Night Watch

Aetherspire Chronicles, Part 1: AWS Lambda
A city in the skies. Two friends who keep it running. This week: why the girl who watches the beacon from night-fall shouldn't spend 72 hours a week awake for six minutes of real work.

The scrape on the wall


Yiezel woke up to the cold and the rail was pressing into her back and a dead lantern was by her side.
For a moment Yiezel did not know how she had ended up on the beacon platform. Then she heard voices from the tier below her. They were not alarmed a little annoyed. Someone was muttering about a scrape that had happened.
Yiezel pulled herself up to the railing. Looked over the edge. On the stone wall right where the lifts pass on their way up through the clouds there was a pale streak. This was a scrape mark in the rock. The UL-114 must have come up out of the clouds enough the night before on schedule but nobody had lit the beacon in time. So the lift had clipped the wall on its way. The UL-114 had been lucky no one had been hurt. Yiezel thought about the beacon and the lift. She was relieved that everything was okay, with the UL-114.
"You fell asleep," said Adrian, finding her still seated on the edge an hour later.
"I was awake for eight hours," replied Yiezel shortly. "And do not remind me that I missed the six minutes."

Six minutes a night

The problem is that lifts have to go through thick cloud to get to the upper city with supplies from the lower tiers. The cloud is so thick that the pilot cannot see anything. So when a lift gets close it sends a signal. Someone has to catch this signal and turn on the beacon so the pilot knows where the wall is.

This happens a times every night. We do not know exactly when it will happen we just know it will be before morning. So someone always has to be awake and ready to catch the signal. This person is probably already really tired from being awake for half the night.
This person is like Yiezel, who has been working for the nine hours. She was only really doing something for six minutes. The rest of the time she was just waiting for a signal that might not even come.
Yiezel said "I am not bad, at watching it is just that the job is not a job."

Just build a bigger bell

Yiezel's suggestions were all variations on the theme of additional watchers. Another person willing to spend long hours on the edge, perhaps, or a louder bell, or even something that did not require waiting at all but simply staying lit through the night.
Adrian was silent for a long time. "You do realise," he said at last, "that you don't want to leave something burning? Every night, for all you know."
"...Yes?"

He retrieved a small, worn notebook from his jacket pocket and scribbled something down before showing her the page. She caught the faint whiteness of a long, pale scar on his forearm before he tucked the notebook back into his pocket.
"What?" she said.
"Nothing." He shut the book with a snap. "Let's talk instead about what you want."



You don't need someone who's always awake

"Here's the thing," said Adrian. "You don't need someone who's always awake"
He paused, considering. "You need something that wakes up."
That, at least, was a beginning. Something that could sleep, and not simply wait, was something that could be had. Something not tied to the slow rhythm of human life. It would not be waiting for hours on end for a signal that might not come, not unless it had to. Something that could answer a beckoning bell, and then go back to waiting. It would be something that had a time to wake, and a time to sleep again.
They needed a Waker.
A Waker was really something. It was not paying attention and it was not waiting around. For most of its life a Waker was not around. Then a signal came the Waker woke up did what it had to do and went back to sleep away. The only time that counted was those seconds when the Waker was awake and that is what people were charged for.
In the world something, like a Waker is called AWS Lambda.. That thing that only existed for a short time to answer a signal that is called a Lambda function.

How the Waker actually works

The mechanics were simple. A signal arrived. This lift at this altitude going up at this speed. The Waker did some calculations figured out how many seconds until it hit the top of the clouds and chose one of three options: turn on the beacon right away wait a bit and check again or do nothing. The lift was still too far away to care about. It sent the response. That was all.
There was no server for Yiezel to look after keep active or charge for each hour. The Waker only lived for those seconds between the signal and the response. Everything else didn't exist all.
That was the idea. Of paying for a server to always be on you paid for the exact moment you needed it. Not waiting around. Getting up working and then going back, to sleep.

The gotcha: the tether

Once the Waker was up and running, Yiezel decided to add one tiny additional feature: checking the manifest that came with the signal against the lift's expected cargo, just to be safe.
The Waker began failing spectacularly. Every single time, it would simply stop in its tracks, unable to finish the task, for reasons that were not immediately apparent.
"You didn't set the tether," was all Adrian had to say when she asked him.
Every Waker needed a tether, which was also known as a timeout. It was how the system knew when to stop a Waker that had wandered off and stopped responding, and return it to sleep. Most of the ones that had been created for this specific task were set to a mere three seconds, a default value that no one had thought to change, because no one had ever thought to need more than three seconds to answer a signal. Three seconds was not nearly enough time to finish even one lift's worth of manifest-checking, but the Waker would not continue past that point no matter how many times it was asked.
"Set the tether. I didn't, once."
He did not say anything else about it. nor did Yiezel ask.
The solution was obvious once one knew to look for it. Simply put, the Waker needed to know how long it had to stay awake to do its job, and the easiest way to do that was to increase the timeout to something reasonable. The lesson was less obvious. A task that failed halfway through was unlikely to be an error in one's logic--more often than not, it was a timeout that had failed to let the task finish.




What it actually costs

Let us return, briefly, to the subject of costs.
The old system had required nine hours of waiting per night, or roughly 270 hours per month, of someone's life that might have been spent doing something more useful. The new system required about four signals per night, and hence about 120 wakeful seconds per month in total. AWS Lambda, the real-world equivalent of the Waker, gave a generous allowance of free monthly seconds, and this was a comparatively small fraction of one percent of that. Even without any tiered free allowance at all, the bare cost of keeping the Waker running for an entire month would be measured in fractions of a cent.
Perhaps a more interesting figure to consider would be the following:
Yiezel used to be awake for 270 hours to catch about 12 seconds of real work
She spent 81,000 times more time waiting than she did actually watching the beacon. And that imbalance--that difference between the time spent waiting and the time spent working--was what the introduction of the Waker was all about. It was why one had to have something that could sleep, so that one did not have to spend hours and hours waiting for a signal that might never come. It was why one needed a Waker, and why one needed something that was only there when one needed it to be.



Where the night went

The next morning, Yiezel found Adrian looking surprisingly well-rested.
"How many lifts came through last night?" she asked.
Adrian had to think about it for a moment. There was not much to think about, really. The Waker had kept no records, as it had known that it should keep none. It had no knowledge of anything but the signals it had received and sent, and those it had answered. It had not kept track of the hours it had spent waiting for signals, since it had not spent any. It had not known what it had done, really, because it had not been there to do it.
"It wasn't there to know," he said at last. "Nowhere. It never existed. Not after it answered."
She narrowed her eyes at him for a moment. "We're going to need somewhere that remembers things."
"Yes." said Adrian. "We are."
---to be continued in part 2, when Yiezel and Adrian go looking for somewhere in Aetherspire that doesn't forget.

Quick notes

  • Each Lambda function sleeps until it is needed, runs long enough to finish whatever it needs to do, and then disappears again, only to reappear at some later date when it is needed once more. You are only billed for the time it was actually running.
  • There is no server that you have to keep running in the background, wasting time and money. Nothing runs, and nothing costs anything, until you need it to.
  • Each Lambda function has a timeout value, which determines how long it will run before being forcibly shut down. This value is much too short to do anything meaningful, by default
  • The most surprising thing about a Lambda function, for someone new to them, is usually the fact that they can run out of time while doing something that takes longer than expected.
  • The biggest difference between a Lambda function and anything else you might have used before is that you are not paying for time spent waiting; you are only paying for the time that you actually use.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article