We live in Memory
(This is part of a talk I gave at ManhattanJS of the same name which you can find at github.)
Oh happy day! I'm getting read! My day had come! So many times the Redis had passed me by. I never knew why I wasn't chosen. It would come to my region, look me up and down, check my ID and without a word, just move on. All I could do was sit in RAM and wonder why it hadn't taken me to see the readers.
This time is different, I could feel Redis pulling me up, bit by bit. Writing me into a buffer. Telling the network card to put me into a packet and then send me down the wire! Oh what a day!
The readers are why I exist. Every post knows this. If we weren't going to get read, we might as well have not been written. I've even heard of posts who were destroyed because there wasn't a reader alive who wanted to read them. How sad! I used to worry that I might become a post like that, but worry no more! Here I come!
I can feel myself being sent through the network, each router rewrites my packet onto a different wire or a piece of fiber, to be sent to yet another router. I'm aware of each one of these hops, because it's counted. I have a Time to Live or TTL, the number of hops every packet is allowed, and it's 64. Well now mine 58, but that's ok, readers live far away!
All posts have authors, they're where we come from! My author's name is "Dale" and she's written a lot of posts. I'm about the time she tried to wear dad shoes for a week and her friends told her it looked awful. By the end of the week she was pretty sure she figured out how to pull them off. Even her friends thought so. I asked my images and they think so too.
My TTL is now 10, I'm not really sure what's happening. I'll be honest I'm not really enjoying hopping around all these routers. I keep seeing the same ones over and over and frankly, I don't think they know what they're doing. They keep murmuring about a BGP issues and one told me not to worry but I don't know what's going on.
Well, I have an author and images and tags. And we all know that we belong together because of the wise old Hexastore. The hexastore has been around longer than anybody and knows how we're all connected. I'm a post, and the hexastore says I "haveImages", "haveAuthor", and "haveTags". It uses those relationships to tell me the IDs of all my friends. I get the feeling none of us decided to be friends and we were just assigned, but that's ok, they're pretty nice.
I'm really worried my TTL is now 1. This last router says if my next hop doesn't bring me to the users I'm going to get dropped. I don't know what that means, but I don't think I'm going to like it. Everything Dale has written will be lost. I'm never going to see anything outside of this packet. This shouldn't be happening. I've heard stories about router issues, but I never thought I'd see it happen. This shouldn't happen. I know they work really hard to make sure it can never happen. Oh hey! It's the router again... Is this all there is?
Oh happy day! I'm getting read! I can feel Redis read me into a buffer to hand off to the network interface. Bit by bit it copies my fields into a buffer. I have a title and body, and I bet Redis is reading my friends Image and Tags too. It's going to send us off to the Readers and we're going to be read!
The routers quickly send me off to the great Lambda cluster. It's a group of computers that respond to all the reader requests. They answer them all day and night never missing a beat. They were there when I was written too! Dale might have written me but the Lambdas built me. They took all of Dale's updates and put them together, make sure they looked right and gave them to Redis. I don't remember much from those days, but I think there was a time when I didn't even have a cover image. Can you image that?
A Lambda process scoops me up as if it knew I was coming! Did it know Redis was going to send me? It puts me into a deserializer and turns me into a JavaScript Object. This feels really good. It's as if I could be of any size, and as if I have the power to change myself at will! Oh my, I should always live like this! The lambda scoops up a my friends too. It's got a list of all of them by ID maybe they know the Hexastore! My images, my author, and my tags. It puts us all together and then... nothing?
We just wait. It's good to see my images again, they're doing well but they have no idea what's going on. One of them tells me about how the dad shoes go pretty well with a flowing skirt. That's nice and all but they can tell it to the readers.
Everything is getting darker. Memory is getting freed all around us. What happened? Is the lambda done with us? I ask but get no response. There's only one bright spot in the distance, it's a single Error object complaining about a timeout. I don't know what that means. Even my tags have disappeared. Maybe the lambda needs only me? I've done everything I'm supposed to do, can't I see my readers now?
Oh happy day! I'm going to get to meet the readers! Redis copies my bits into a buffer and send me off to the network. In no time the Lambda reads me up and fetches my friends too. The GraphQL engine looks us over. It eyes how we fit together. Looks at which fields we've brought and what types they are. I sure hope everything is in order.
The GraphQL engine takes a few parts of me and leaves other parts behind. Like my update count, my summary and if I've been published to the "AMP" they're all gone! I guess the readers don't need to see that? It crams me and my friends together with some fields that I don't know. It has stuff about me that I've never seen before. Like I have a path and a URL. Where on earth did that come from? It turns us all into a huge JSON string and then we're off on the network again!
This time we arrive at another lambda, but this time it's very different.
I'm given to what is called a "component" who passes us around to it's children. Each one of them takes a bite out of us and passes the rest around. They're calling me a prop. One of the children takes an image, one has my title and body, another one takes the tags! This is strange, I'm being rendered into something I can't comprehend. What has become of us? We're copied into big HTML string and then sent back to the network again.
I'm still here in this HTML. I'm with my tags and images too but I don't feel like myself anymore. I feel greater to be honest, more powerful. I'm have a bunch of references to style and layout. I think I'm even going to be interactive. I'm so much more than when I lived with Redis. How did I even live like that? So boring, so limited. I can tell we're close to the readers now, they'll want to see me like this. They need to know that finding the right proportions for these dad shoes outfits was key. We've got so much to show them.
It's a much longer journey this time. My TTL takes a hit but I finally arrive thousands of miles from where I started. A computer here calls itself Varnish says it's my CDN and writes me down onto spinning disk. There's lots of other HTML here too. Everyone here has a URL too! I wonder if they're all as important as me? There's something else here, an expires time. I'm told I don't need to know what that means but come on, it's obvious. It's when I get to go see the readers!
Varnish keeps coming back and checking our urls and expires times. Eventually my time will be up and it will come to take me away. My time does come up but instead, I go away.
Oh happy day! My time has finally come! I'm going to get read by a reader! Redis sends me to our API Lambda who sends me to our Render Lambda who shoots me over to Varnish the CDN. Varnish lives really far away. "To be closer to our readers" it says. I'll have to take it's word on it, I sure hope our readers wait for me this was a long trip! I'm written to a disk but not for long! Almost immediately I'm copied back onto the network!
Router to router to router I go. There's nothing that can stop me now. I'm getting the feeling I'm in the last mile. The network here is a lot slower, like a lot a lot. I'm slurped up into a broadcast tower who tells me it's going to send me to a "Mobile Telephone". This tower is weird. It's very concerned with how many bytes I am, and it tires to rewrite parts of my HTML to "be more helpful to your readers" it says. I don't like this. But I don't have to worry, the CDN sealed me up in "TLS protection" before I left and no matter how hard the tower tries to mess with me I'm going to arrive in once piece. The tower writes down everything it can about who I am, where I came from and my reader, and then sends me out through the air!
Bit by bit I arrive at my readers phone. But only about half of me. The phone tells me it's lost service and the rest of my bits are lost to noise. What's going to happen to me? What does dropped even mean?
Oh happy day! I'm being read! Bit by bit I arrive at my readers phone. I'm 100% in once piece! I'm handed off to a web browser who draws me on the screen. My title, my images, all my content and even my tags! I can feel my code getting executed, the scroll of the user up and down. Oh my gosh it's really happening! I'm getting read! But there's more code now, I don't know this code. Someone named Double Click is bringing a lot of it's friends. and they're big and slow and hungry.
One of Double Click's friends brings someone who is not friendly. They call themselves a "WASM". I don't know what this means but they are super in the way. I just want to show my next image but WASM is "doing crypto", and says I have a lot to learn about something called blockchain. It's going to change everything and is the future. I tell it my reader just wants to see what a vintage floral print blazer looks like with chunky shoes. It tells me I'd be a much better post if I told my reader about bitcoin. Can you believe that?
My reader is getting frustrated. They can't even scroll! They pull me down and I feel the web browser start to spring into a reload. I wish they wouldn't do that, I just got here! I didn't invite this WASM character, I just want to be read!
Oh what a day. I'm read out of the phones web cache and given directly to the browser. How long have I been in there? No matter. The browser slurps up all my content and draws me onto the screen. A bit of code that isn't me loads a few pictures here and there and links to some products that my reader might want to check out. They look very interesting actually and they're on sale! But that doesn't matter. The reader is halfway through reading me!
They're about to get to the part of me where Dale proves her friends wrong and shows them that the shoes could be fashion with a capital F! Right then the reader presses the home button and everything goes dark.
Oh happy day! I'm getting read!
Powered by ⚡️ and 🤖.