The growth of Serverless ecosystem in recent times is tremendous, with respect to the features, support, monitoring and etc. This article is purely based on my experience and readings with respect to Web Applications. As of today, many traditional applications struggling to modernize themselves and on the other side many of the new applications are built on microservice architecture and they been deployed in containers by default (again emphasizing on Web Applications). Topics for today is, whether you choose to build and host on Containers or would you like to build it as a serverless application. When you talk about traditional vs Serverless then serverless is a clear winner in modern development, and I feel Containers are somewhere in between
“Containers won the battle, but will lose the war to serverless” — Simon Wardley
Saying that, now straight away jump into the discussion points
- What is Serverless Application
- Architecting Modern Applications (JAM Stack, MongoDB Stitch)
- Containers vs. Serverless
- Tools and references
“Serverless doesn’t mean that you don’t have servers, it is just means that you don’t need to worry about those servers” - John Papa
Serverless Applications
Servers challenge us with additional cost, difficult to setup and a struggle to maintain. And that’s the simple reason why you look for serverless solutions, just keeping scaling and few others out. By the definition from AWS, Serverless is the native architecture of the cloud that enables you to shift more of your operational responsibilities to AWS, increasing your agility and innovation. Serverless allows you to build and run applications and services without thinking about servers. It eliminates infrastructure management tasks such as server or cluster provisioning, patching, operating system maintenance, and capacity provisioning. You can build them for nearly any type of application or backend service, and everything required to run and scale your application with high availability is handled for you. Serverless enables you to build modern applications with increased agility and lower total cost of ownership. Building serverless applications means that your developers can focus on their core product instead of worrying about managing and operating servers or runtimes, either in the cloud or on-premises. This reduced overhead lets developers reclaim time and energy that can be spent on developing great products which scale and that are reliable
In relevance to this blog, most of us today write serverless code in conjunction with code written in traditional server style, such as microservices. For example, part of a web application could be written as microservices and another part could be written as serverless code. Alternatively, an application could be written that uses no provisioned servers at all, being completely serverless and I believe that is going to be the future
There were few challenges which was stopping us in the past from moving to Serverless are now getting resolved one after other. As an example, Azure functions comes with a great tooling support which helps developers to develop and debug serverless functions locally without any struggle
The JAMstack
A pure Serverless architectures are application designs that incorporate third-party “Backend as a Service” (BaaS) services, and that include custom code run in managed, ephemeral containers on a “Functions as a Service” (FaaS) platform. But here in this blog we are skipping the backend part little and there are more providers for BaaS today and they are always easy to plugin
For those not familiar with the term, JAM means JavaScript, API’s, and Markup. Translated into non-Acronym speech, means a client-side site where the initial HTML page is not web server like ASP.NET, or Ruby on Rails, or Express. This can be a little confusing, but you just have to understand the two purposes of web servers like ASP.NET. First they serve up assets (HTML, JavaScript, CSS, fonts, etc.) and second they reply to AJAX calls to store and retrieve data. This second function is what we do a lot of with our React and Angular etc. applications, and we mostly don’t think much about the first purpose. With the JAMstack we can still make those AJAX calls, but something like Netlify handles serving up our HTML, JavaScript, and CSS etc. And all those assets need to be static (which usually isn’t a problem)
It is very important to choose the correct architecture when you looking to build serverless applications. The JAMstack helps you to keep it simple and get it correct. The Stack emphasis a 100% server-side processes abstractions into microservice APIs. Using the JAMstack has huge benefits on performance, scalability, security, ease of deployment, and cost. I won’t really dig into details of all these, but just want to let you know that using platforms like Netlify along with JAMstack applications will ensures above mentioned benefits (a must read book on JAMstack - link)
MongoDB Atlas offering
Today, one of the commonly used DB Service Provider (DBaaS) is MongoDB Atlas platform. The DBaaS platform Atlas also provide ability to build serverless applications. As you see in the screen grab you can build APIs using serverless functions available with MongoDB Stitch and hook them with the Atlas Cluster backend.
Stitch functions runs as simple JavaScript (ES6) functions in Stitch’s serverless environment and serves applications with Server-side logic, or enable Data as a Service with custom APIs. Serverless platforms on top of MongoDB helps reducing time to market, operational cost and development cost.
In short Stitch functions can be invoked through HTTP endpoints or through external services like AWS API gateway. The collection of functions can be grouped through a Stitch App and the same can be hooked up with an authentication provider (a third party provider like gitHub, Google or Facebook, or we can implement a custom authentication)
Containers vs. Serverless
AWS offers computing services in the form of IaaS with its famous EC2 container service, FaaS in the form of its serverless Lambda functions, and CaaS with its newly-released Fargate product. Among these three computing services to choose from within the AWS cloud environment, where EC2 has the most operational burden, AWS Lambda has the least, and AWS Fargate is somewhat in the middle on the spectrum. Fargate is a type of ECS (Elastic Container Service) where is takes little bit of Infrastructure burdens as you don not need to manage any EC2 instances.
In a container-based architecture, the number of containers deployed is determined by the developer in advance. In contrast, in a serverless architecture, the backend inherently and automatically scales to meet demand
Containers are constantly running, and therefore cloud providers have to charge for the server space even if no one is using the application at the time. There are no continued expenses in a serverless architecture because application code does not run unless it is called. Instead, developers are only charged for the server capacity that their application does in fact use
Couple of key cons of Serverless are Cold Start and Vendor lock-in, but there are modern tools and frameworks can help you to overcome these problems. Example Serverless (link) and Spring Cloud Functions by Pivotal
Conclusion
Lambda functions could be considered a more viable option, but they have their limitations. In the case of AWS Lambda some of these limitations include a 512MB ephemeral disk space limitation and 50MB deployment package size among, and a few others. Given all that, you no longer have to worry about provisioning your containers and defining scaling rules, you would still have to worry about such limitations.
It is always been told in the past that Serverless is a great choice for an Internet of Things (IoT) and can help us performing little tasks based on a trigger. And also it is perceived like, Serverless is ideal when development speed and cost minimization is paramount and if you don’t want to manage scaling concerns. But given the background above on modern Web Application Development techniques like JAMstack and the growing initiatives like CloudState, makes it highly possible to use Serverless as your platform to build large scale web applications
Reference
- https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-serve-static-website/
- https://developer.okta.com/blog/2019/03/21/build-secure-microservices-with-aspnet-core
- https://dzone.com/articles/squeeze-aws-lambda-for-everything-its-worth
- https://www.youtube.com/watch?v=WBEzGFpAnhY (Data API with MongoDB Stitch)
- https://www.thundra.io/
- https://www.cloudflare.com