Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Có hai phiên bản của Cloud Functions for Firebase:
Cloud Functions (thế hệ thứ 2), triển khai các hàm của bạn dưới dạng dịch vụ trên Cloud Run, cho phép bạn kích hoạt các hàm đó bằng Eventarc và Pub/Sub.
Cloud Functions (thế hệ thứ nhất), phiên bản ban đầu của các hàm có số lượng trình kích hoạt sự kiện và khả năng định cấu hình hạn chế.
Bạn nên chọn Cloud Functions (thế hệ thứ 2) cho các chức năng mới bất cứ khi nào có thể. Tuy nhiên, chúng tôi dự định tiếp tục hỗ trợ Cloud Functions (thế hệ thứ nhất).
Trang này mô tả các tính năng được ra mắt trong Cloud Functions và so sánh giữa hai phiên bản sản phẩm.
Cloud Functions (thế hệ thứ 2)
Cloud Functions là dịch vụ Hàm dưới dạng dịch vụ (FaaS) thế hệ tiếp theo của Firebase. Được xây dựng trên Cloud Run và Eventarc, Cloud Functions (thế hệ thứ 2) mang đến cơ sở hạ tầng nâng cao và phạm vi bao phủ sự kiện rộng hơn cho Cloud Functions, bao gồm:
Được xây dựng trên Cloud Run: Các hàm được xây dựng bằng Cloud Build và triển khai dưới dạng các dịch vụ Cloud Run bằng môi trường thực thi Cloud Run mặc định.
Điều này cho phép bạn tuỳ chỉnh hàm của mình như một dịch vụ Cloud Run. Tham khảo tài liệu Cloud Run để khám phá các lựa chọn định cấu hình dịch vụ của bạn, chẳng hạn như giới hạn bộ nhớ, biến môi trường, v.v.
Thời gian xử lý yêu cầu lâu hơn: Chạy các tải công việc có yêu cầu dài hơn, chẳng hạn như xử lý các luồng dữ liệu lớn từ Cloud Storage hoặc BigQuery.
Kích thước phiên bản lớn hơn: Chạy các khối lượng công việc lớn hơn trong bộ nhớ, có mức sử dụng điện toán cao và song song.
Cải thiện tính đồng thời: Xử lý nhiều yêu cầu đồng thời bằng một phiên bản hàm duy nhất để giảm thiểu số lần khởi động nguội và cải thiện độ trễ.
Quản lý lưu lượng truy cập: Chia lưu lượng truy cập giữa các bản sửa đổi chức năng khác nhau hoặc khôi phục một chức năng về phiên bản trước.
Tích hợp Eventarc: Hỗ trợ gốc cho các trình kích hoạt Eventarc, mang tất cả hơn 90 nguồn sự kiện mà Eventarc hỗ trợ đến Cloud Functions.
Hỗ trợ CloudEvents trên diện rộng: Hỗ trợ CloudEvents theo tiêu chuẩn ngành trong tất cả các thời gian chạy ngôn ngữ, mang đến trải nghiệm nhất quán cho nhà phát triển.
Vì Cloud Functions triển khai các hàm dưới dạng dịch vụ trên Cloud Run, nên Cloud Functions chia sẻ hạn mức và giới hạn tài nguyên với Cloud Run. Xem phần Định mức.
Bảng so sánh
Tính năng
Cloud Functions (thế hệ thứ 1)
Cloud Functions
Sổ đăng ký hình ảnh
Container Registry hoặc Artifact Registry
Chỉ vào Artifact Registry
Hết thời gian yêu cầu
Tối đa 9 phút
Tối đa 60 phút đối với các hàm được kích hoạt bằng HTTP
Tối đa 9 phút đối với các hàm được kích hoạt bởi sự kiện
Tài khoản dịch vụ*
Tài khoản dịch vụ Google App Engine (PROJECT_ID@appspot.gserviceaccount.com)
Tài khoản dịch vụ điện toán mặc định của Google Cloud (PROJECT_NUMBER-compute@developer.gserviceaccount.com)
Kích thước phiên bản
RAM tối đa 8 GB với 2 vCPU
RAM tối đa 16 GiB với 4 vCPU
Đồng thời
1 yêu cầu đồng thời cho mỗi phiên bản hàm
Tối đa 1.000 yêu cầu đồng thời cho mỗi phiên bản hàm
* Đây là tài khoản dịch vụ mặc định dùng để truy cập vào Firebase hoặc Cloud API từ một hàm đang chạy. Firebase Admin SDK sử dụng khoá này khi bạn khởi chạy mà không có đối số.
Nếu được nhắc, hãy chọn tài khoản thanh toán được liên kết với dự án Google Cloud của bạn.
Trong bảng Bộ lọc, trong phần Nhãn, hãy thêm một bộ lọc nhãn có khoá goog-managed-by và giá trị cloudfunctions.
Các điểm hạn chế
Cloud Functions for Firebase (thế hệ thứ 2) không hỗ trợ các sự kiện Analytics.
Mặc dù Cloud Functions for Firebase (thế hệ thứ 2) hỗ trợ các sự kiện chặn xác thực, nhưng không hỗ trợ cùng một nhóm sự kiện cơ bản Authentication như thế hệ thứ nhất.
Tuy nhiên, vì các hàm thế hệ thứ nhất và thế hệ thứ hai có thể cùng tồn tại trong cùng một tệp nguồn, nên bạn vẫn có thể phát triển và triển khai Analytics và các trình kích hoạt Authentication cơ bản trong thế hệ thứ nhất cùng với các hàm thế hệ thứ hai.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-03 UTC."],[],[],null,["\u003cbr /\u003e\n\nThere are two versions of Cloud Functions for Firebase:\n\n- **Cloud Functions (2nd gen)** , which deploys your functions as services on Cloud Run, allowing you to trigger them using Eventarc and Pub/Sub.\n- **Cloud Functions (1st gen)**, the original version of functions with limited event triggers and configurability.\n\nWe recommend that you choose Cloud Functions (2nd gen) for new functions\nwherever possible. However, we plan to continue supporting Cloud Functions\n(1st gen).\n\nThis page describes features introduced in Cloud Functions and\nprovides a comparison between the two product versions.\n\nCloud Functions (2nd gen)\n\nCloud Functions is Firebase's next-generation\nFunctions-as-a-Service offering. Built on Cloud Run and\nEventarc, Cloud Functions (2nd gen) brings enhanced\ninfrastructure and broader event coverage to Cloud Functions, including:\n\n- **Built on Cloud Run** : Functions are built with Cloud Build and deployed as Cloud Run services using the default [Cloud Run execution environment](//cloud.google.com/run/docs/about-execution-environments). This gives you the ability to customize your function as you would a Cloud Run service. Refer to Cloud Run documentation to explore options for configuring your service, such as [memory\n limits](//cloud.google.com/run/docs/configuring/services/memory-limits), [environment variables](//cloud.google.com/run/docs/configuring/services/environment-variables), and so forth.\n- **Longer request processing times** : Run longer-request workloads such as processing large streams of data from Cloud Storage or BigQuery.\n- **Larger instance sizes**: Run larger in-memory, compute-intensive, and parallel workloads.\n- **Improved concurrency**: Handle multiple concurrent requests with a single function instance to minimize cold starts and improve latency.\n- **Traffic management**: Split traffic between different function revisions or roll a function back to a prior version.\n- **Eventarc integration** : Native support for Eventarc triggers, bringing all 90+ event sources supported by Eventarc to Cloud Functions.\n- **Broader CloudEvents support** : Support for industry-standard [CloudEvents](https://cloudevents.io/) in all language runtimes, providing a consistent developer experience.\n\nSee the [comparison table](#comparison-table) for details.\n\nBecause Cloud Functions deploys functions as services on Cloud Run,\nCloud Functions shares resource quotas and limits with\nCloud Run. See [Quotas](/docs/functions/quotas).\n\nComparison table\n\n| Feature | Cloud Functions (1st gen) | Cloud Functions |\n|-------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| Image registry | Container Registry or Artifact Registry | Artifact Registry only |\n| Request timeout | Up to 9 minutes | - Up to 60 minutes for HTTP-triggered functions - Up to 9 minutes for event-triggered functions |\n| Service account\\* | Google App Engine service account (\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e@appspot.gserviceaccount.com) | Google Cloud default compute service account (\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e-compute@developer.gserviceaccount.com) |\n| Instance size | Up to 8GB RAM with 2 vCPU | Up to 16GiB RAM with 4 vCPU |\n| Concurrency | 1 concurrent request per function instance | Up to 1000 concurrent requests per function instance |\n\n\\* This is the default service account used to access Firebase or Cloud APIs\nfrom a running function. It is used by the Firebase Admin SDK when you\n[initialize without arguments](/docs/admin/setup#initialize-sdk).\n\nPricing\n\nFor pricing information, see [Firebase pricing plans](https://firebase.google.com/pricing#cloud-functions).\n\nYou can view your costs associated with Cloud Functions as follows:\n\n1. Go to the [Cloud Billing Reports page](https://console.cloud.google.com/billing/reports) in the Google Cloud console.\n2. If prompted, select the billing account associated with your Google Cloud project.\n3. In the **Filters** panel, under **Labels** , [add a label filter](//cloud.google.com//billing/docs/how-to/reports#filters) with the key `goog-managed-by` and the value `cloudfunctions`.\n\n| **Note:** If you are using Cloud Functions for Firebase (1st gen) and are interested in Cloud Functions, see [Upgrade 1st gen Node.js functions to 2nd gen](/docs/functions/2nd-gen-upgrade).\n\nLimitations\n\nCloud Functions for Firebase (2nd gen) does not provide support for Analytics\nevents.\n\nThough Cloud Functions for Firebase (2nd gen) supports authentication blocking\nevents, it does not support the same set of basic Authentication events as\n1st gen.\n\nHowever, because 1st gen and 2nd gen\nfunctions can coexist side-by-side in the same source file, you can still\ndevelop and deploy Analytics and basic Authentication triggers in 1st gen\ntogether with 2nd gen functions."]]