amplitude / Amplitude-Node

Server-side Node.js SDK for Amplitude
MIT License
67 stars 20 forks source link

Identify event taking too long to resolve #125

Closed delucca closed 2 years ago

delucca commented 3 years ago

Hi everyone.

I've implemented the Amplitude NodeJS SDK in my application. It is a simple GraphQL server that serves content to one of our websites.

I've been facing a big issue with the Amplitude SDK. When I dispatch an identify event, it usually takes too long to resolve. Sometimes that hangs my server completely. This is especially complicated because sometimes (when Amplitude hangs the identity response for too long) my server mixes two user's requests, leading to potentially problematic issues.

Regarding "mixing two requests" I've already debugged and found out that it is indeed related to Amplitude. I've created a simple bash test script that dispatches 2 requests at the same time. Whenever I add the Amplitude identify event, that issue happens, when I remove it, the issue disappears (same request, same payload, same endpoint, only with/without Amplitude identify event)

How can I solve this? It is possible to dispatch the identify event alongside the event itself? If I don't identify the users, I would have some kind of trouble when logging the event? Since my users are already identified by my front-end application, I wonder if I truly need the identify in the backend too.

Thanks for your attention.

ajhorst commented 3 years ago

Hi @delucca. Are you saying that the Amplitude Node SDK mixes up data between the two requests? Does that only happen with identify events and regular events, or have you noticed it happening with two regular events? That shouldn't be happening, so I will debug this issue as well.

delucca commented 3 years ago

Hi @delucca. Are you saying that the Amplitude Node SDK mixes up data between the two requests? Does that only happen with identify events and regular events, or have you noticed it happening with two regular events? That shouldn't be happening, so I will debug this issue as well.

Hi, thanks for your response.

No, the problem is that in some cases (not every time) Amplitude takes so long to respond to the identify event that this "freezes" my application, making the framework I'm using (NestJS) mixes two requests.

The problem is related to the fact that the identify is (for some reason) really slow. While testing, in some cases the identify command took 2-3 seconds to receive an answer from Amplitude.

I know that the "mixing two requests" is a bug related to NestJS, not Amplitude. But I would like to understand why the identify event of Amplitude takes so long to resolve, while any other event is always executed quickly. Also, I would like to know if I really need to trigger the identify event. Since my users are already being identified in my front-end application, I still need to identify them also in the backend?

ajhorst commented 3 years ago

Hi @delucca

That is really unusual that you're having this issue just with identify requests. Under the hood, identify and event logs go to the same Amplitude endpoint and are handled almost exactly the same way, so I would expect any issue with one taking too long to resolve would also affect the other. I'll look into any possible cause of just identify calls being slow.

That said, if your UI sent an Identify event for a certain user, then as long as your Node JS code is logging events with that user's user_id, you don't need to call identify again from the backend. A user's identify attributes will be attached to all events with their user_id going forward.