Serverless Architectures with Azure Functions
Infrastructure patterns are constantly evolving.
- Through the 1980s, mainframes were the center of gravity for all business processes.
- Servers became smaller and more specialized throughout the 1990s.
- A majority of new servers were virtualized in the 2000s.
- In the 2010s, the bulk of new virtual machines are being spun up in the cloud.
- Now, we’re witnessing a shift from entire virtual machines to efficient virtualized “containers”.
Throughout all of this, the scope of solutions has become more granular and purpose-built. No matter what, we’ve always had a level of infrastructure to worry about. Whether managing the monolithic servers or orchestrating a fleet of microservices, there have always been performance, scalability, security, and costs to optimize.
Now, companies are starting to adopt the “serverless” computing pattern, which foregoes most infrastructure concerns. Just like Infrastructure-as-a-Service (IaaS) is significantly easier to maintain than classic capex infrastructure and Platform-as-a-Service (PaaS) is even easier to maintain than IaaS, “serverless” computing is the easiest of all to maintain.
Of Course It’s Not Literally Serverless
Let’s start with “serverless” in quotes. What we’re talking about are fleets of self-organizing compute resources. There’s still servers somewhere; we just don’t care about them as long as our code runs.
Just as “the cloud is just somebody else’s computer that you rent by the hour”, I would say that “serverless is somebody else’s computer with no commitment”. Instead of caring where code runs, serverless means we only care that it runs reliably. The cloud consists of millions of computers; serverless takes advantage of that scale and eliminates the overhead, running your code while billing for microfractions of a penny.
It always seemed wasteful to purchase server racks that sat with CPUs idling below 10% usage. We’ve consistently paid for oversized machines, often stretched to be available in multiple regions, just in case.
Serverless architectures are becoming a go-to method for building autoscaling, cost-effective CPU-bound applications.
There’s an analogy that some servers are “pets” that you name and care about. Other servers are “cattle” that come and go. I propose that serverless architectures are like “ants”: they’re everywhere, productive, and you never get to know them.
Amazon Web Services is responsible for much of the early momentum around serverless computing, with their Lambda product. AWS provides a series of hooks for running event-driven code based on file uploads, server activity, or web requests.
Azure Functions are billed based on “Gigabit seconds” (Gb-s), which is a multiple of the number of seconds run times the average volume of memory consumed. The first million requests per month are free and pricing then starts at $0.000016 / GB-s. That’s right: 1.6 thousandths of a penny. The current pricing is practically free for many workloads, including real-world website protection.
What Workloads Are Ideal For Serverless Architectures?
The following scenarios are well-suited for serverless architectures:
1. Multimedia Processing
Imagine everytime you upload an image, you need to optimize it, resize it, rotate it, or maybe perform OCR on it. That can be automated using a few dozen lines of code.
2. Scheduled Tasks
Need to send an email, calculate a report, or run multi-stage workflows every morning? There are alternatives like Azure Scheduler and runbooks, but Azure Functions has the lowest barrier of entry.
3. Search Engine Crawlers
Most enterprise search platforms are heavy and oversized to allow many threads crawl and index content at once. Instead of paying for expensive infrastructure, crawlers can efficiently crawl thousands of data sources in parallel, save results to Azure BLOB storage or DocumentDB, then index that content using Azure Search.
4. Lightweight Web Services
Azure Functions can be triggered using REST-based webhooks. These are easy to write and maintain, integrating with or even replacing heavier Service-Orientation Architecture.
5. Electronic Data Interchange
Need to download, decrypt, unzip, and normalize data from a vendor or client every day? Write that code in a high-level language like C# or Python, schedule it, and deploy it today. For better integration, set up a webhook so your partner can notify your process when new data is available for real-time refreshes.
There are countless uses for serverless architectures built with Azure Functions. Between the flexibility, speed to deploy, and low costs, it’s one of the best tools in our cloud toolbox.