简体中文 / [English]


Some Fun Ways to Use Cloud Functions - Writing Code Like Writing a Blog

 

This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to the original Chinese version. I am continuously working to improve the translation.

Cloud functions (FaaS) are lightweight, stateless, and reusable code snippets running in the cloud. Without managing servers, you simply write and upload your code, then get the desired results. Using cloud functions allows businesses and developers to focus on code and business logic instead of server or infrastructure maintenance, while also promoting better code decoupling and reusability.

Recently, with the rise of containerization technologies, major cloud providers have long launched their own Function-as-a-Service (FaaS) or Serverless offerings.

In fact, function computing services are also a very flexible option for individual developers, enabling you to write code as effortlessly as writing a blog, without worrying about infrastructure operations.

These days, I don’t even bother buying a domestic VPS (not even a student plan — too much hassle to maintain). High-performance VPS instances are usually expensive, and for resource-intensive services, a well-equipped HomeLab is far more cost-effective.

Take Alibaba Cloud’s block storage as an example: the price of SSD Cloud Disks is as high as 1 CNY per GiB per month.

During the summer of 2023, you could buy a 7.68TB WD SN640 enterprise-grade SSD (China version, 5-year warranty) on Taobao for only 1,600–1,900 CNY. Over five years, that’s just ~0.0043 CNY/GiB/month (= ~30 CNY / 7.68TB / month).

On top of that, domestic cloud bandwidth and traffic are notoriously expensive due to the business-to-residential bandwidth subsidy model. For instance, Alibaba Cloud charges up to 2,000 CNY/month for a 100Mbps dedicated bandwidth, or 0.8 CNY/GB on a pay-as-you-go basis.

Under such “enterprise-focused” pricing models, it’s nearly impossible for individual developers to afford extensive usage of domestic cloud resources.


Beyond cost savings from pay-per-use pricing and elasticity, cloud functions also offer high availability and stable service delivery. (Alright, though they did have a recent outage (link) that I got caught in)

Cloud functions are essentially container hosting, so many advantages of Docker containers also apply.

For example: easy deployment (no more messy configurations on a single machine), strong security isolation (one broken container won’t bring down the whole host), and high independence.


Any service that doesn’t run for too long, is inherently an HTTP service, isn’t called too frequently, and doesn’t require large disk space, can be hosted on cloud functions.

State persistence can be achieved by mounting NAS or OSS for storing data.

My own approach is to deploy services requiring public access or low-frequency background tasks onto cloud functions to ensure high availability.

Other services that need long-running processes or heavy resource consumption are hosted on my HomeLab at home, accessed via a private VPN. This internal network setup ensures security, limits exposure, simplifies migration or updates, and avoids widespread outages from a single point of failure.

For example, I’ve deployed the following services on Alibaba Cloud’s Function Compute (FC):

Under current traffic levels, I barely use up Alibaba Cloud’s free tier quotas. I only pay minimal outbound traffic fees—sometimes less than 1 CNY per month.

If you have generous quotas, for functions with large container images (like my captcha recognition backend), you can create a secondary service that periodically pings it to keep it “warm” and avoid long cold-start delays.

This article is licensed under the CC BY-NC-SA 4.0 license.

Author: lyc8503, Article link: https://blog.lyc8503.net/en/post/cloud-native/
If this article was helpful or interesting to you, consider buy me a coffee¬_¬
Feel free to comment in English below o/