It occurred to me this morning that there are actually quite a few parallels between functional programming and infrastructure design and management.
It all started by what I realized that I said while talking about environments: Production is meant to go from one stable, working, vetted version of code to another stable, working, vetted version of code. Any state between those two is invalid and should (preferably) never occur.
If you cycle on that again, you start to see that most deployment processes you know about violate this One Basic Rule(tm).
I posit that if you are deploying new code to currently running hosts that are handling traffic, you are doing it wrong.
Think about it like this: what is the one core feature of every highly scalable functional programming language? Every one has (or has developed patterns which essentially create) immutable values.
So when we scale this out of software and apply it to infrastructure, your code is the value of your server. If you are changing the value of your server while other processes are trying to access it, you’re going to run into concurrency issues. Ask any developer about sharing data between threads, and they’ll quickly tell you it’s difficult. Why, then, do we improperly share data between releases of our software?
The simple answer is that you have two options for atomic deployments that follow the rules of immutability:
- Drop the servers you are deploying to out of the flow of traffic. This is the easiest, but still fails to honor the spirit of immutability because the value of the server is still changing, it’s just changing while nobody is looking.
- Spin up new instances, and slowly work them into live traffic, confirming along the way that you are in fact getting the expected behavior out of the code.
Now, I know this is all hand-wavy because it glosses over the important aspect of data migration: I don’t have an answer there, yet. I suspect the true answer to that part of the solution would be something to the effect of being able to seamlessly decouple your entire system from write traffic (using a request proxy which could ‘pause’ calls) for some period of time while data updates are done.
What if, to create a truly fault tolerant design, you simply create a nearly 100% asynchronous API. All requests come in and go into a process queue, and are handled from there. This way you are never required to turn off traffic to do an atomic update of your software because you can simply tell it to stop processing while the update progresses.
This week, I am in Louisville, KY at Code PaLOUsa! Next week, I leave for SXSW Interactive in Austin, TX. Right as I get back from SXSW, I take off for Midwest PHP in Minneapolis, MN.
I’m speaking at Code PaLOUsa and Midwest PHP, so if you’re around, be sure to come check out why you should care about development environments, and how to go about implementing them in your organization.
I love to meet new people, so if you see me, please come say “Hi!!” and introduce yourself.
This weekend I was invited by a few friends from the Ann Arbor PHP User Group to join them on Saturday night and figure out something to work on together.
TLDR: I need to do this more. It was immensely fun.
So it started off with a few ideas flying around on what to build, and then I’d mentioned that I have wanted to build an app for estimation poker since forever. Also — it seems I can be somewhat persuasive.
So the four of us sat down (Jonathan, Kelly, Jason and I) and we sorted out what our MVP (Minimum Viable Product to those of you who don’t live in startup land) was going to be. We settled on features and the basics of the protocol, and then had to pick technology. I’d seen that Ember.js seems particularly well built for building a multiple concurrent user system, so I suggested that, and I believe it was Jonathan who suggested Node.js for the back end, and of course — socket.io for communication. Jonathan and Jason would pair to build the back end, while Kelly and I would take the divide and conquer approach for the front end. With all of that decided, there was only one other choice to make…
Because it’s a fun name to say, that’s why.
So as of today, the minimum viable pieces are actually working. You can check out the github repository, or even see the live demo up on Heroku. I’m hoping we can maybe look at using it at work to help encourage participation during planning meetings perhaps, but even if that never comes to fruition, it has certainly been a fun project to work on, even just as far as it is now. It still has a lot of rough edges, but you can see it starting to come together.
So, I’m trying to make a point to have something posted every Monday — so for lack of better topic, my friends at work reminded me of a fun one: I used to smoke.
Normally, not a big deal, you quit, woohoo. But of course: I quit like a nerd.
Let’s not kid around: cigarettes are scary addictive. They controlled a lot of how I made my daily decisions on where to go and what to do. I suspect many smokers are like this, even if they’re not ready to admit it.
Want to go visit family? How long will you stay? Do you smoke around them? What about a movie? Is it too long? What about that restaurant? Oh, they don’t have a smoking section. Nevermind.
It was late 2009, April and I had just found out our first child was on their way to meet us, and so we needed to “become parents.” Yes, that sounds ridiculous even now, but it’s how it made sense in my head. It was time to start thinking longer term. One of those thoughts was:
I REALLY NEED TO QUIT SMOKING
So I started doing research, and I found out about electronic cigarettes. Then I did a lot more research.
Then I bought this:
And actually, what I bought was specifically (though an older packaging):
Titan 510 Starter Kit
Two batteries, two atomizers, mine actually came with a charging case for the batteries, which was quite helpful, as the batteries (at least then) didn’t seem to last particularly long (but then, my memory is also pretty fuzz at this point).
I got a “Tobacco” flavored “nic juice” (what they call the fluid that contains the nicotine, flavoring, and propylene glycol), liked it, and after a week of struggling, was happily 100% on e-cigarettes. Yes — I had withdrawal when switching entirely to e-cigarettes. Let’s be very clear here: nicotine is not the only thing in cigarettes that you are addicted to. If there was any question in your mind, let me make that clear. You will go through withdrawal switching to e-cigarettes from traditional cigarettes.
Once I had made the transition, a few weeks after that my body realized I was no longer “smoking” and … started, we will say, “removing” some of the “toxins”. Gross. Anyway, not long after, I had to start figuring out a long term plan to get off of nicotine completely. Now here came an issue: The nic juice I liked came in 24mg, 18mg, and 12mg “flavors” but that is as low as it went. They didn’t offer 8mg, 4mg, or 0mg versions, so I had to start trying to branch out my flavor choices into one that could support me stepping down to a 0mg nicotine fluid.
After many rounds, I was forced to give up on the pre-made option, as none of them either A) tasted good to me, or B) had 0 nicotine versions. So I did what any programmer does when nothing out their suits their needs: I rolled my own!
Let’s take a side-step and look at what nic juice is made of:
- Propylene Glycol
- Vegetable Glycerin
Now I’m not sure of the exact origin of the science of all of this, but it seems that they figured out they could extract nicotine from tobacco leaves with a Propylene Glycol based solution. I was able to find a business would send me a (relatively speaking) GIANT bottle of (I think) 36mg nicotine solution. Now this is not for the faint of heart. If I had spilled this solution on my hands, could have possibly died from nicotine poisoning. Kind of scary, but if you take appropriate precautions, it’s fine.
So I took this essentially flavorless nic juice, and had to cut it down. I didn’t need 36mg nic juice. But if I used 1 part nic juice and 2 parts propylene glycol (Remember to get USP grade, kids. It’s going in your body, it needs to be food-safe.), I would get a nice 12mg nic juice to start with. To that, I kid you not, you add candy flavoring. YES! CANDY FLAVORING! 😀 My flavor of choice, which tasted the best to me after all the ones I tried: grape.
That’s right, I smoked grape nic juice. And it was hilariously awesome when others caught a whiff of it, as it completely threw people off. Having full control of the nic juice let me slowly titrate myself down to 0mg, freeing myself from the horrors of smoking. Or so I thought.
2 weeks of vaping 0mg grape nic juice, and I started to feel a little silly. I needed to just stop, as there was now no gain from the action, aside from all the trouble associated with trying to create, maintain, and fill my own containers with candy flavored propylene glycol. It was a mess, it took quite a bit of time, I needed to be done.
So I quit.
Second reality check of the whole thing: even though the chemical addition was gone, my body rebelled against losing the habit of smoking. I had all of the classic nicotine withdrawal symptoms, with irritability being close to the top of them. It was a very tense week or two at my house.
But then I was free.
Now, nearly four years later, I think you could count on one hand the number of cigarettes I’ve had since — and that’s only because I can’t remember well enough to say I haven’t had any since I quit. I don’t remember any. You will occasionally find me standing by the smokers, wistfully wishing they wouldn’t taste horrible if I tried one, breathing in their smoke.
What does this have to do with programming?
Well — not a lot. But I think I told you that story to tell you this: there is always a way to accomplish something. Don’t let “it’s hard” stop you. Not get derailed because not all the options you want are present. Persist. I went to ridiculous lengths to quit smoking, because it was important enough to do so. Don’t let “can’t” stop you if it’s important. Find a way.