jitsu icon indicating copy to clipboard operation
jitsu copied to clipboard

Give transformations access to key value store (Redis)

Open azhard4int opened this issue 3 years ago • 3 comments

Problem

What problem this feature is going to solve. Why this problem is important

Jitsu does not support session id generation on the server side/client side. As of now, we are doing it on a client side, but when using a strict mode, we cannot send the session id from the client side. Doing it on a server side would ease the workflow for us and other Jitsu users who are building their products on top of Jitsu.

Solution

Proposed solution: architecture, implementation details etc

For the session ID feature on the server side, the finger-printing mechanism Jitsu is using for anonymous id can be used for generating a unique session ID. The session ID should be stored in Redis cache set with TTL 30 minutes. Here is how the flow would be like:

Screenshot 2022-07-06 at 11 27 54 AM

For the server side configuration, Jitsu can provide option to create session on server side using a boolean flag. Based on the flag value, the session process will work.

@vklimontovich @absorbb

azhard4int avatar Jul 06 '22 08:07 azhard4int

+1

zkid18 avatar Jul 06 '22 14:07 zkid18

Thank you for reporting this! We should implement this via plugins, it doesn't make sense to add this logic to a core processing pipeline. Here's a architecture:

Give transforms access to Redis

The code could look like:

const userFingerprint = $.user_agent + $.ip + ...;
let sessionId = $kv.get(`session_${userFingerprint}`);
if (!sessionId) {
    sessionId = Math.random().toString(36).substring(2)
    $kv.set(`session_${userFingerprint}`, sessionId, {ttlMs: 1000*60*30})
}
$.sessionId = sessionId;
return $;

$kv global should be an instance of:

export type KeyValue = {
  get(key: string): any
  set(key: string, value: any, opts?: {ttlMs?: number})
}

We should think through how it should work in multi-tenant environment to avoid key collisions. Probably each destination should have an option keyPrefix, which we should set to projectId for multitenant installations

vklimontovich avatar Jul 06 '22 14:07 vklimontovich

TWIMC, this feature will be in beta around 31st of Aug 2020

vklimontovich avatar Aug 25 '22 19:08 vklimontovich