Guide To CircleCI Webhooks Features And Best Practices

Profile Picture

Fikayo Adepoju Oreoluwa

Mon Oct 25 2021

Now that you have gotten all the information you need to get started with CircleCI webhooks, examined the different types of use cases for the technology, and implemented CircleCI webhooks with a simple tutorial, now let's look at what you should consider when moving your webhooks to a production environment.

Development environments are very predictable, and the conditions under which your webhooks operate are controlled. However, in a production environment, issues related to system resources, security, response latency, and other things can arise. For guaranteed uptime of your webhooks, you need to make sure that you're taking the necessary preventive and corrective steps.

Getting started with CircleCI webhooks

Learn what is the difference between CircleCI webhooks and API and how to integrate CircleCI webhooks in your external workflows and applications.

Mon Oct 11 2021

The top 5 use cases for CircleCI webhooks

Discover what are the top use cases for CircleCI webhooks. Get an idea on how you can take advantage of them in your next project!

Fri Oct 15 2021

CircleCI Webhooks Tutorial

A step by step tutorial on how to set up CircleCI webhooks. How to create a webhook? How to validate it works? How to implement CircleCI webhook security?

Wed Oct 20 2021

CircleCI Webhooks Features

FeatureNotes
Webhook ConfigurationAdmin interface only. No API endpoint.
Request MethodPOST
Hashing AlgorithmSHA-256
Webhook Timeout5 seconds
Retry LogicThe exact details of the retry policy are not currently documented, and are subject to change during the preview period by CircleCI's team.
Manual RetryNot Available
Browsable LogNot Available
AlertingNo alerts of failure are sent

Best Practices for Working with CircleCI Webhooks

Local troubleshooting before deployment

The first box you want to check is local troubleshooting. You need to ensure that you have properly tested your webhooks to make sure that the following operations are taking place:

  • The webhooks are being received at the webhook URL.
  • There are no 404 errors, i.e. the webhook URL can be found.
  • If you're authenticating your webhooks, ensure that they pass the authentication checks.
  • Assert that your webhooks have the desired effect on your external client.

Webhooks require a live, publicly accessible HTTPS URL to function which makes them tedious to troubleshoot in local development environments. This is why you don't want to debug errors in production, as this can have a very damaging impact on your business.

To overcome the frustrations of debugging, the Hookdeck CLI is available to help you generate a webhook URL that tunnels your webhooks to your local development server. You can also examine your webhook payload and inspect the request headers.

CLI Reference

CLI Reference for the Hookdeck CLI

Asynchronous webhook processing

CircleCI has a five (5) second timeout for each webhook request sent. This means that if CircleCI does not receive a response within this time, it will assume that the delivery has failed and retry the webhook at a later time.

If you will be receiving a lot of webhooks, you want to ensure that you're processing them as fast as you can and returning a response within CircleCI's timeout range. Processing speed is often limited, but you can ensure that you're returning a response to CircleCI as fast as possible by processing your webhooks asynchronously.

Asynchronous processing can be introduced into your infrastructure through the use of message queues like Amazon SQS or RabbitMQ. A message queue helps to quickly ingest your webhooks from CircleCI and return a response immediately. You can then serve your webhooks to your destination client at a rate that it can handle, and avoid server crashes due to traffic spikes.

Introduction to Asynchronous Processing

Read an introduction to asynchronous processing. We compare the differences between synchronous and asynchronous and what are the alternative solutions to handling asynchronous processing.

Thu Apr 22 2021

Introduction to Messages Queues

Learn what are message queues, what are producers and consumers, the advantages of using message queues and what frameworks and services you can use to implement message queueing.

Mon May 24 2021

CircleCI webhook security using webhook signatures

Security is of the utmost importance in a production environment. Because your webhook URL is publicly accessible, any person or web agent can send a request to it. Attackers can craft a malicious web request in order to inject a harmful payload into your system. This is why you need to verify that the source of your webhook requests is CircleCI.

Fortunately, CircleCI webhooks provide a way to achieve this. When you add a secret token to your CircleCI webhook form, CircleCI cryptographically encrypts the payload and puts the signature in the circleci-signature header.

This way, you can use the same secret token on your client to verify that your webhook is indeed from CircleCI.

In our CircleCI webhook tutorial, we demonstrated how this can be done using the HMAC algorithm. You can also find more information about this on CircleCI's webhook documentation page.

CircleCI Webhooks Tutorial

A step by step tutorial on how to set up CircleCI webhooks. How to create a webhook? How to validate it works? How to implement CircleCI webhook security?

Wed Oct 20 2021

Server IP whitelisting

Another way to ensure that your webhooks are originating from CircleCI is through IP whitelisting. You can configure rules on your server that uses an allow list of IP addresses to ensure that only requests from CircleCI's servers are accepted by your endpoint.

Every other request from unknown sources will be automatically bounced by your server and will not make it to your endpoint.

Retrying failed webhooks

CircleCI treats every webhook that returns a non-2xx HTTP status code as a failed webhook. CircleCI webhooks also have intelligence built in to try these failed webhooks at a later time.

However, for guaranteed self-healing of failed webhooks, you might also want to mitigate this issue with a custom retry system just in case CircleCI does not retry your failed webhook.

Retry systems can be simple cron jobs, but the most effective ones keep a repository of failed events to be retried with their payload, and also use intelligent timers to trigger the retries. You can also combine your retry system to your message queue when processing your webhooks asynchronously.

Retrying failed webhooks ensures that data integrity issues do not arise in your API. Failed webhooks in commercial or financial systems can lead to users not getting value for goods and services paid for, thus you want to ensure that you're not dropping any webhooks.

How to Solve Webhook Data Integrity Issues

Learn what causes data integrity issues when working with webhooks and what are the preventive, and corrective strategies to solve them.

Mon Aug 16 2021

Logging and monitoring CircleCI webhooks

To ease troubleshooting your CircleCI webhooks in production, a logging system is highly recommended. You need to be able to trace your webhook requests and be aware of their status at all times, especially in situations where they fail.

When webhooks fail, information about their failure helps in debugging and fixing them. You can perform logging using different types of strategies, from writing logs to simple flat files to using a standard logging service.

Idempotency for webhook duplicates

A very important check to implement when working with CircleCI webhooks is ensuring that a single webhook is not processed more than once. Oftentimes, CircleCI can send a webhook request more than once and you need to ensure that you're not duplicating the impact of the webhook on your destination application.

Duplication of webhook processing can quickly compromise your data and make your application lose its integrity. To help with this, CircleCI sends an id property in the webhook payload. This id can be saved to the database when a webhook is received and compared against new webhooks to avoid duplication.

Conclusion

Following best practices allows you to benefit from the wealth of experience professional developers have to offer, and avoid mistakes that could cost you a lot of business. In this article, we have looked at best practices you should consider taking when deploying your CircleCI webhooks to production environments.

A good number of these best practices can take a significant amount of time and expertise to set up properly. If you want to build fast and ensure that you're taking into consideration best practices for your webhooks, give Hookdeck a try today.

Hookdeck has in its suite tools like a retry configuration system, a rate limiter, queueing service for asynchronous processing, and an intuitive dashboard that provides clear visibility into your GitHub webhooks.

Happy coding!

Try Hookdeck Today

Instantly & reliably manage
your webhooks

Learn More
Related Guides

Getting started with CircleCI webhooks

Learn what is the difference between CircleCI webhooks and API and how to integrate CircleCI webhooks in your external workflows and applications.

CircleCI
Guide
Mon Oct 11 2021

CircleCI Webhooks Tutorial

A step by step tutorial on how to set up CircleCI webhooks. How to create a webhook? How to validate it works? How to implement CircleCI webhook security?

CircleCI
Guide
Wed Oct 20 2021

The top 5 use cases for CircleCI webhooks

Discover what are the top use cases for CircleCI webhooks. Get an idea on how you can take advantage of them in your next project!

CircleCI
Guide
Fri Oct 15 2021