Issue with count of visits

Hi,

Basically i am sending same data to both my internal datalake(aws) and matomo platform. But i am seeing differences in number of unique_visitors from my datalake and matomo analytics. there is a huge differences between my datalake numbers and matomo analytics numbers.

I am running this query on my datalake to get the total number of unique visitors.

select ab_group,
       count(distinct user)
from ecomm_events 
where customer_id = '123456799999999' and 
          event_date  between  '2019-08-21' and '2019-09-29'   
      
group by 1

when i run this query in my datalake, i am receiving this result.

a ==> 36987
b ==> 66589

But

In the same time frame, if i see the unique visitors in matomo ab-experiments, i am seeing these numbers

a ==> 37,258
b ==> 37147

I am not sure whether issue with the data or issue with the query i am running in my datalake.
Can anyone tell me how matomo is calculation unique visitors from the events data.?