Traffic Overload Prevention

In order to use the Traffic Overload Prevention feature, you must have a GoSquared Account and Varnish 4 on your application. To setup the feature you will 1) add your gosquared credentials, 2) add VCL for overload prevention, and then 3) call the new VCL in your default VCL file. Optionally, you can 4) edit the default Overload page that will be shown to your customers. The following page will walk you through each step.

Step 1: Add GoSquared Credentials

First, you need to add a file to the repo called: gosquared-visitor-count

The content of file should be: <overflow number> <ID> <secret>

  • Where “overflow number” is the max number of customer you want on your site
  • Where “ID” comes from end of URL when you are logged into gosquared
  • Where “secret” is a string with no spaces that only you know

Example: 300 GSN-000000-M a000000000bc111111111d00000

Where to find Gosquared ID:


Step 2: Add VCL for Overload Prevention

In the Varnish folder of your repo, add section-user-throttling.vcl

The contents of this file are here.

Step 3: Include Overload Prevention VCL

In the varnish file of your repo, edit the default.vcl to add the following:

Be sure to update the secret and threshold values to match what you added for your GoSquared Credentials.

Note about Section-Visitors-Version:

Section-Visitors-Version determines the name of the cookie issued to visitors to remember whether they have been granted access or blocked due to exceeding the threshold.

When the threshold is increased, users with the “blocked” cookie will be given an opportunity to be granted access when their cookie expires after 3 minutes.

When the threshold is decreased, users with the “allowed” cookie will still have access until their cookie expires after 1 hour but this may put the site under too much pressure. Change the Section-Visitors-Version to invalidate all existing issued cookies and immediately enforce the new threshold.

In our example VCL we’ve used POSIX time to determine the version as it is a new value every second. If you prefer, you can choose to increment another way.

Note about Section-Visitors-Fallback-Block-Percentage:

As GoSquared is an external service, it is possible that the current user count may not be available and the system will not be able to determine if the threshold has been exceeded to make an appropriate decision to allow or block a new visitor. In this situation, new visitors will be randomly assigned to the “allowed” or “blocked” state based on the value of Section-Visitors-Fallback-Block-Percentage. That is, a percentage of “10” will randomly block 10% of new visitors until the current GoSquared user count data becomes available. A value of “0” will allow all new visitors and a value of “100” will block all new visitors.

Optional Step 4: Edit the Overload Page

The default Overload Page will show your customers a blank page with unstyled text saying “threshold exceeded”. To implement the overload prevention feature, first update the VCL with this default setting. Then go in and edit the VCL. Specifically, line 16 of the above gist that will be added to the default.vcl calls the html that will be displayed. To add your own HTML, simply replace the <html>threshold exceeded</html> with your own html.