DEV Community

Cover image for How I Built a Serverless Function Without Knowing It, I Think*
Gerald Nash ⚡️
Gerald Nash ⚡️

Posted on

How I Built a Serverless Function Without Knowing It, I Think*

It’s the weekend after a week full of exams. I’m exhausted and am just waiting to graduate high school. But, like any other developer I feel the urge to go ahead and start another weekend project. I’m learning some pretty interesting stuff in AP Calculus, but I get tired of doing algebra during homework at times. I think to myself: Why not build something that does my math homework for me?

Not a Bad Idea

That’s where I got the idea to build Newton, a really micro micro-service for math. I wanted to make it easier for developers to do math without being constrained by codebase sizes or non-existant APIs in their preferred language.

Newton API Front Page

So what makes it interesting? Other then being super cool and functional, of course, Newton requires no storage space other than its source files. It doesn’t access or modify a database, and it doesn’t even dynamically create configuration files or any of the matter. Each request and response is protected by Zeit Now’s HTTPS encryption. Plus, it runs solely on simple GET requests.

I didn’t think much of those characteristics, but after a bit of interaction with the tech community I think Newton is a serverless function.

Explain "serverless architecture" to me like I'm five years old. #DevDiscuss

— The Practical Dev (@thepracticaldev ) April 5, 2017

@ThePracticalDev Very small machines on a network; LOTS of them work at the same time. But their brains are very small, they can't remember what they did!

— Eric Elliott (@_ericelliott) April 5, 2017

Eric Elliott gave an unexpected yet informative response. Newton fits those characteristics. Zeit abstracts global hosting for Now, so that satisfies the machines on a network. Newton is a relatively small package (~3.3kB), so that fits the small brain, and like I said it doesn’t access or process persistant memory. Seems like serverless to me.

Shoulder Shrug

Anything else?

@ThePracticalDev Write code as a bunch of function and then pretend infrastructure doesn't matter.

— Elliot Blackburn (@elliotblackburn ) April 5, 2017

That seals the deal. I use Now, because I don’t have to worry about anything other than how my code runs. And, Newton does one thing: math.

Wait, math is a lot of things.

Hmm...

We get the point. But just to be sure, I took to r/serverless.

My Reddit Question

Eh, that answer is good enough for me.

Why not?

So, in the end I built a small serverless function as a weekend project to help me do my math homework and help others make cool things. Newton has grown to become more popular than I initially expected, and I‘d love to witness its expansion and see what others make with it.

And don’t forget: it’s serverless, I think.

You're Awesome

Thanks for reading! As always, you’re awesome.

For more information on serverless architecture, start here.

Top comments (6)

Collapse
 
kaqqao profile image
Bojan Tomic

The GIFs are so distracting and annoying I couldn't read the whole thing...

Collapse
 
danielw profile image
Daniel Waller (he/him)

So it's basically a pure function you hooked up to a webservice...Serverless seems like a silly term though (clearly there's a server involved) stateless maybe? Or even stackless?

But in any case it's really cool and you can scale that shit into oblivion at super tiny costs! Nice work :)

Collapse
 
benfavre profile image
Webdesign29

how is a publicly accessible and hosted API anywhere near serverless ...
I mean WTF ...

Collapse
 
thibmaek profile image
Thibault Maekelbergh

I don't think you understand what serverless means in modern web development.

Collapse
 
keppla profile image
Benjamin Köppchen

So, another definition of serverless might be "it's not only 'share nothing', but 'nothing to share'?" :)

Collapse
 
developius profile image
Finnian Anderson

This is really cool! Love the simplicity and the GIFs to explain above 😉👍