Gunakan diagram perbandingan di bawah untuk membantu Anda memutuskan kebijakan mana yang akan digunakan untuk
kasus penggunaan pembatasan laju Anda:
Kuota
SpikeArrest
Gunakan untuk:
Membatasi jumlah panggilan proxy API yang dapat dilakukan oleh aplikasi developer atau developer selama
jangka waktu tertentu. Kebijakan SpikeArrest lebih cocok untuk pembatasan laju pada interval waktu yang lebih singkat seperti detik atau menit. Pertimbangkan Kuota jika penghitungan yang akurat adalah persyaratan.
Membatasi jumlah panggilan API yang dapat dilakukan terhadap proxy API di semua konsumen
selama jangka waktu tertentu (biasanya singkat). Kebijakan Kuota lebih cocok untuk menetapkan batas pada interval waktu yang lebih lama seperti hari, minggu, bulan, atau tahun.
Jangan gunakan untuk:
Jangan gunakan untuk melindungi backend target proxy API Anda dari lonjakan traffic.
Untuk itu, gunakan kebijakan SpikeArrest.
Jangan gunakan untuk menghitung dan membatasi jumlah koneksi yang dapat dilakukan aplikasi ke backend target
proxy API Anda selama jangka waktu tertentu. Catatan: Untuk kasus penggunaan yang memerlukan
penghitungan yang akurat, gunakan kebijakan Kuota.
Menyimpan jumlah?
Ya
Tidak
Praktik terbaik untuk melampirkan kebijakan:
Lampirkan ke ProxyEndpoint Request PreFlow, biasanya setelah
autentikasi pengguna.
Hal ini memungkinkan kebijakan untuk memeriksa penghitung kuota di titik entri proxy API
Anda.
Lampirkan ke ProxyEndpoint Request PreFlow, biasanya di
awal alur.
Kebijakan ini memberikan perlindungan lonjakan di titik entri proxy API Anda.
Kode status HTTP saat batas telah tercapai:
429 (Layanan Tidak Tersedia)
429 (Layanan Tidak Tersedia)
Sebaiknya Anda tahu:
Penghitung kuota disimpan di Cassandra.
Konfigurasi kebijakan untuk menyinkronkan penghitung secara asinkron untuk menghemat
resource.
Sinkronisasi penghitung asinkron dapat menyebabkan penundaan dalam respons pembatasan laju, yang dapat memungkinkan panggilan sedikit melebihi batas yang telah Anda tetapkan.
Memungkinkan Anda memilih antara algoritma "penghalusan" atau algoritma penghitungan efektif. Yang
pertama memperlancar jumlah permintaan yang dapat terjadi dalam jangka waktu tertentu, dan yang kedua
membatasi total jumlah permintaan yang dapat terjadi dalam jangka waktu tertentu, tidak peduli
seberapa cepat permintaan tersebut dikirim secara berurutan. Selain itu, perataan tidak dikoordinasikan di seluruh
Prosesor Pesan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-10 UTC."],[[["\u003cp\u003eThis content focuses on the Quota and SpikeArrest policies within Apigee and Apigee hybrid, which are used to manage request thresholds.\u003c/p\u003e\n"],["\u003cp\u003eThe Quota policy is recommended for use cases requiring precise request counting over longer durations like days, weeks, months, or years, offering accurate counting across all regions.\u003c/p\u003e\n"],["\u003cp\u003eSpikeArrest is better suited for rate limiting over short intervals, such as seconds or minutes, and for protecting backend services from sudden traffic spikes, but its request counting may not be entirely accurate due to its use of a Redis cache.\u003c/p\u003e\n"],["\u003cp\u003eBoth the Quota and SpikeArrest policies trigger a \u003ccode\u003e429\u003c/code\u003e (Service Unavailable) HTTP status code when request limits are reached, indicating a temporary denial of service.\u003c/p\u003e\n"],["\u003cp\u003eShared flows and chaining proxies can be utilized to protect slower backends without impacting API performance.\u003c/p\u003e\n"]]],[],null,["# Comparing Quota and SpikeArrest policies\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\n| **Key Point:** The [Quota](/apigee/docs/api-platform/reference/policies/quota-policy) and [SpikeArrest](/apigee/docs/api-platform/reference/policies/spike-arrest-policy) policies both count requests and take action if a specified request threshold is exceeded. Be aware, however, that the mechanisms by which these policies count requests are not the same.\n|\n|\n| While SpikeArrest maintains counts with high reliability, it is designed to use a\n| [Redis\n| best-effort cache](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/other_protocols/redis) to store its counts. Because the cache is not replicated, there are cases where counts may be\n| lost, such as a restart of the cache servers, or other rare cases.\n|\n| For these reasons, we recommend\n| against using SpikeArrest for use cases that require accurate counting. Only the synchronous\n| Quota policy offers accurate counting across all regions in a given timeframe.\n\nUse the comparison chart below to help you decide which policy to use to\nfor your rate limiting use case:\n\n| **Tip:** You can also use the following to protect slow/sluggish backends without impacting the performance of the APIs:\n|\n| - [Creating reusable shared flows:](/apigee/docs/api-platform/fundamentals/shared-flows) Combine policies and resources into a shared flow that you can consume from multiple API proxies, and even from other shared flows.\n| - [Chaining API proxies together](/apigee/docs/api-platform/fundamentals/connecting-proxies-other-proxies): Specify that one proxy is the target endpoint of another, effectively connecting the two proxies in a proxy chain. Chaining proxies in this way can help you avoid a network hop, and so improve overall performance."]]