Home ci 07. pricing: Manage and optimize usage for Edge Middleware

07. pricing: Manage and optimize usage for Edge Middleware

Last updated on Aug 05, 2025

Manage and Optimize Usage for Edge Middleware

Edge Middleware is a powerful tool that allows you to enhance your application's performance and functionality. However, understanding how it works and how to optimize its usage is crucial for managing costs effectively.

Table of Contents


Introduction

Edge Middleware is priced based on the number of times your middleware is invoked and the CPU time it consumes. By understanding these metrics, you can better manage your usage and reduce costs.


Pricing Metrics

Invocations

  • Description: The number of times your middleware is invoked.
  • How It Works: Your middleware is called for every route in your project by default.
  • Optimization Tip: Use the config matcher property to limit routes where your middleware is invoked.

CPU Time

  • Description: The time your middleware spends computing responses to requests.
  • How It Works: CPU time refers to actual net CPU usage, not execution time. Operations like network access do not count towards CPU time.
  • Optimization Tip: Avoid using fetch() in middleware as it slows down the TTFB.

Optimizing Middleware Invocations

  1. Group by Count: View total invocations across all projects to identify high-use areas.
  2. Use Projects: Check invocations per project to pinpoint where optimization is needed.
  3. Config Matcher: Limit middleware invocation by specifying routes that require it.

Optimizing Middleware CPU Time

  1. Average CPU Time: See the average computation time across all projects in your team.
  2. Project CPU Time: Review total CPU time for each project to identify high consumers.
  3. Avoid Fetch: Use efficient data fetching methods to reduce TTFB delays.

Getting Started

  1. Set up your Next.js project with Edge Middleware.
  2. Use the Epycbyte dashboard to monitor invocations and CPU time.
  3. Apply optimization strategies based on your findings.

By understanding these metrics and applying optimizations, you can effectively manage and optimize usage for Edge Middleware, ensuring better performance and cost efficiency.