aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming
  • Public Cloud

Celebrating Pi Day With Cloud Functions

  • aster.cloud
  • March 15, 2022
  • 3 minute read

March 14 is Pi Day, an annual celebration of the mathematical constant π. We’re doing a few experiments with the new Cloud Functions (2nd gen) this year to showcase the new serverless platform.

Serverless π calculation

Can we go serverless to calculate π? There is a relatively new algorithm called the Bailey–Borwein–Plouffe formula (BBP formula) to calculate digits of π without computing the preceding digits, which means we can run many calculations in parallel and gather the results later. We can build a MapReduce pipeline to get the numbers. Cloud Functions (2nd gen) supports larger instances (16 GB memory and 4 vCPUs) and extends the max function execution duration to 60 minutes from 9 minutes so we can push the limits further.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

Here’s the architecture we built. We used Node to implement the functions.

Distributed Pi

The calculation runs as follows.

  • The processRequest function to create and submit tasks (e.g., calculate X digits from offset Y) to PubSub.
  • The calculateOffset function gets triggered by PubSub, computes digits, and stores the result to Firestore.
  • A separate controller function keep-watch monitors Firestore and triggers combineResults once all tasks are complete, storing the final output in Cloud Storage as a text file.

How long does it take? It takes about 45 minutes to calculate 64 million digits.

Pi Table

Unfortunately, the BBP formula is computationally more complex than other algorithms used in record-breaking attempts (such as our last 31.4 trillion record), so it is unlikely we can use this method to establish a new record. However, the extended runtime in Cloud Functions makes running many new applications possible, including this experiment.

Read More  New Cloud Shell Editor: Get Your First Cloud-native App Running In Minutes

Serverless Pi API

We’ve also built a new API to serve digits of π. We previously used Google Kubernetes Engine (GKE), but we have migrated the service to Cloud Functions 2nd gen. We also rewrote the API program to fetch data from Cloud Storage instead of Persistent Disk.

Pi API

We’ve reduced the total monthly expenses from about 9,000 US dollars to 450 US dollars by changing the architecture.

  • Storage cost: The most significant cost factor is the disk. The previous configuration used a Zonal SSD Persistent Disk to store the digits of π, and it’s 50 TB with 50 trillion digits in plain text, which costs 8,500 US dollars a month. We’ve moved all the data to Cloud Storage. We’ve also changed the object format to a compressed file so that the 50 trillion digits consume 21 TB instead of 50 TB. With these changes, storage cost is about 400 US dollars a month, which is 95% saving.
  • Compute cost: Cloud Functions also helps reduce cost. There is no base CPU cost for Cloud Functions as it only charges when processing requests. Previously with GKE, we always had four instances in 2 zones that would cost 391 US dollars per month with the e2-standard-4 instance type. We estimate that the monthly cost would be around 7 US dollars for 1 million requests, achieving 98% saving.

The new service architecture is also faster and more robust as it runs in multiple regions. The global HTTP(S) load balancer chooses the closest region automatically and improves latency. The API function has a small cache inside and returns a response without accessing the Cloud Storage bucket on a cache hit.

Read More  Smart Communications, Inc. Dials into Google Cloud AI to Help Personalize Digital Services for Filipinos

Live demo

We have a live demo using the new API where you can listen to music created by the digits of π or watch an animation of transitions of the numerical sequence. We host the entire 50 trillion digits from the 2021 world record for the demo. You can also call the API directly from the command line:

curl "https://api.pi.delivery/v1/pi?start=0&numberOfDigits=100"

The source code of the API service and the demo are available on GitHub. We use Terraform to manage the infrastructure, and we’ve published the scripts as well, so it’s a great place to learn with actual examples.

Happy Pi Day!

 

By Emma Haruka Iwao, Developer Advocate
Source Inside Vancouver


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • Cloud Functions
  • Google Cloud
  • Pi Day
  • π
You May Also Like
View Post
  • Public Cloud

Connecting AI agents with unstructured data using Google Cloud Storage MCP Servers

  • June 10, 2026
Data center
View Post
  • Data
  • Public Cloud

Data Sovereignty in Spain. It’s Not Just About the Law, It’s About Efficiency

  • June 3, 2026
View Post
  • Data
  • Platforms
  • Public Cloud

PayPal’s historically large data migration is the foundation for its gen AI innovation

  • March 4, 2026
Google Cloud and ElevenLabs
View Post
  • Public Cloud
  • Technology

ElevenLabs Partners with Google Cloud for Cloud Services and the Latest NVIDIA Blackwell GPUs

  • February 26, 2026
View Post
  • Public Cloud

Delivering a secure, open, and sovereign digital world

  • February 12, 2026
View Post
  • Public Cloud

Formula E and Google Cloud Announce Multi-Year ‘Principal Partnership’

  • January 26, 2026
View Post
  • Public Cloud

Sawasdee Thailand! Google Cloud launches new region in Bangkok

  • January 23, 2026
View Post
  • Public Cloud

Retailers Help Mitigate Risk with Oracle’s AI-Driven Supply Chain Collaboration

  • January 11, 2026

Stay Connected!
LATEST
  • 1
    Expectations vs. Reality: The AI We Thought We’d Have in 10 Years
    • June 19, 2026
  • digital-nomad-freelancer-worker-2151205464 2
    One paperwork problem – Get your Digital Nomad Visa employment documents fast from UK, EU or Singapore
    • June 16, 2026
  • 3
    Samsung Art Store Brings Art Basel to Homes Worldwide With New Curated Collection
    • June 15, 2026
  • 4
    You Do Not Need to Invest in the IPO of SpaceX, Anthropic, and OpenAI
    • June 10, 2026
  • 5
    The consequences of relying on AI for accurate news
    • June 10, 2026
  • 6
    Connecting AI agents with unstructured data using Google Cloud Storage MCP Servers
    • June 10, 2026
  • 7
    WWDC26: Apple unveils next generation of Apple Intelligence, Siri AI, powerful parental controls, and an expansive set of software improvements
    • June 8, 2026
  • 8
    IBM and Google Cloud Announce Strategic Partnership to Scale AI with Human Expertise and AI‑Powered Delivery
    • June 4, 2026
  • Data center 9
    Data Sovereignty in Spain. It’s Not Just About the Law, It’s About Efficiency
    • June 3, 2026
  • 10
    Ink vs Pixels. What you miss versus what you are actually missing.
    • June 1, 2026
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • 1
    Banks race to patch new cyber vulnerabilities, and other cybersecurity news
    • May 25, 2026
  • pope-leo-xiv-cq5dam-1500.844 2
    Pope Leo XIV to Publish First Encyclical on Artificial Intelligence and Human Dignity on 25 May
    • May 22, 2026
  • 3
    Portfolio to Clients, and is Strengthened by Ongoing Project Glasswing Work
    • May 20, 2026
  • reMarkable Paper Pure 4
    Everything The reMarkable Paper Pure Actually Does
    • May 14, 2026
  • 5
    Scaling cloud and AI: Microsoft Azure’s commitment to Europe’s digital future
    • May 11, 2026
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.