Difference between using webhooks vs sending http request directly from photon?

photon
Tags: #<Tag:0x00007fe21f71ed10>

#1

I’m using a photon to read Dust sensor values and send them to my external API for storage. I can do this 2 ways:

  1. Using TCPClient and sending an http POST to the API endpoint directly from photon.
  2. Photon publishes an event and a webhook set up on the particle device cloud handles the http POST.

I’m wondering what the pros and cons of each are? Are webhooks handled by the particle device cloud generally preferable?


#2

I am facing a similar decision and I think that while it is sometimes good to have a data path and a management path to a device - its not always practical.

Pros for Webhook

  • End to end security
  • Included in deviceOs so no flash space lost to a client library needed on photon
  • Webhooks can be reported on in the console for auditing or tracking

Cons of Webhook

  • 4 messages published per 4s limit

Cant think of any other compelling reasons against webHooks?


#3

Can you explain this please? I am with you on the rest. I wasn’t aware that the webhook (SSE?) was included in the maximum 4 per second burst rate.


#4

When considering that the device needs to publish an event in order to trigger the webhook the limit indirectly applies to the webhook for this one device but of course if the webhook was used by multiple devices it could be triggered way more often than just 4 timpes over 4 seconds.

The OP’s question has set the scope of the answer as how to get data from the device (data source) to a custom server (data sink) and hence the webhook path is limited by the “weakest” link (Particle.publish()).


#5

I understand about the device publish limits but are the webhook events included in the device send rates limits? And if so, how are these rate-limited publishes measured and shown in the console (did I read somewhere that they aren’t but should be?).


#6

No as @ScruffR said it the publish rate per device that is rate limited - so 100 devices publishing will publish a maximum of 400 messages in 4s, the web hook will send them all on as they arrive.


#7

Thanks - that’s what I thought then.


#8

Hi @corneliusellen and welcome to Particle’s community!
I’ll add what I can below.

Cons of using a TCP client on the photon:

  • you need to manage the connection on the photon
  • you need to learn how to use the tcp client lib
  • no end to end encryption

Cheers
Gustavo.


#9

Webhooks are easy to implement and maintain.
There are slight service interruptions, but those are fixed quickly by Particle.
You can also track the daily/monthly usage for each Webhook on the Particle Console.
The 1 second update rate limit for Particle.publish (req’d for Webhook) should be plenty for most devices, such as your dust sensor.


#10

All these answers really helped me with understanding the differences between the two approaches. Thanks all!

As I’m thinking about different ways to connect my photons with other devices (like led lights, a fan, my dust sensor), I’m also wondering about use cases where one would want to have 2 photons talk directly to each other over HTTP/TCP instead of going through the cloud. Both of these approaches require wifi, so I don’t really see a benefit to the 2 photons connecting directly over wifi.


#11

If you’re looking at connecting devices locally, you should take a look at the gen3 hardware using mesh.