PP
← All work

AI Product UI

ChatCDP

An LLM chat surface that brokerage analysts trust enough to use daily.

Client
Tier-1 retail brokerage
Role
Sole frontend architect
Timeline
4 months
Team
1 FE, 2 BE, 1 PM

Problem

Brokerage analysts spent hours pulling cohorts from a customer data platform, writing repetitive SQL, and clicking through dashboards to answer the same questions every week. Product wanted a chat surface that let them ask in plain English and get answers backed by real data, not hallucinated text.

Compliance review meant the chat had to do three things at the same time: no fabrication, traceable numbers, and recoverable errors. We had to design streaming responses, structured-output rendering, embedded BI when the answer naturally maps to a chart, and a recovery path for every failure mode that hits during the trading day.

The bar was "a tool a senior analyst would not be embarrassed to use in front of a managing director." I owned the full frontend architecture: the SSE event contract, the structured output renderer, the Superset embedding pattern, and the primitives library used by three internal chat surfaces.

Constraints

  • Banking compliance review of every UI surface.
  • No silent fabrication. Every claim cites a query result.
  • Sub-second time-to-first-token.
  • Apache Superset embedded inline, not in a separate tab.
  • Strict structured-output rendering. Cards, tables, charts as first-class blocks.
  • Errors recover, they do not crash the conversation.
  • Design system enforced.

Decisions

Chose

Server-Sent Events with a typed event contract (status, partial, complete, error)

Considered

Raw WebSockets, polling, plain JSON responses

Why

SSE is one-way, reconnects automatically, and maps cleanly to LLM token streams. WebSockets added complexity for nothing. Polling felt wrong at the latency we wanted.

Chose

Structured output blocks rendered as native React components inside the stream

Considered

Always-text responses or always-JSON responses

Why

Real analyst workflows mix prose and tables. Forcing one shape made the surface feel either chatty or robotic. Letting the model emit typed blocks gave us a rich surface without losing conversational flow.

Chose

Apache Superset embedded via signed iframe

Considered

Re-rendering charts client-side from raw query results

Why

Superset already had the queries, access control, and audit trail compliance had blessed. Rebuilding that on the client would have re-fought every audit conversation.

Chose

Reusable primitives library (streaming renderer, retry, cancel, error recovery, memory)

Considered

Ad-hoc components per surface

Why

Three internal teams wanted variants of the same chat. Building primitives once meant the second and third surfaces shipped in weeks, not months.

Code sample

hooks/useSSEStream.ts
import { useEffect, useRef, useState } from 'react'

type Event =
  | { type: 'status'; status: 'thinking' | 'searching' | 'ready' }
  | { type: 'partial'; text: string }
  | { type: 'complete'; messageId: string }
  | { type: 'error'; code: string; message: string }

export function useSSEStream(url: string, body: unknown) {
  const [text, setText] = useState('')
  const [status, setStatus] = useState<'idle' | 'streaming' | 'done' | 'error'>('idle')
  const [error, setError] = useState<string | null>(null)
  const abortRef = useRef<AbortController | null>(null)

  function cancel() {
    abortRef.current?.abort()
    setStatus('idle')
  }

  useEffect(() => {
    const controller = new AbortController()
    abortRef.current = controller
    setStatus('streaming')
    setText('')

    fetch(url, {
      method: 'POST',
      headers: { 'content-type': 'application/json' },
      body: JSON.stringify(body),
      signal: controller.signal,
    })
      .then(async (res) => {
        if (!res.body) throw new Error('No response body')
        const reader = res.body.getReader()
        const decoder = new TextDecoder()
        let buffer = ''
        while (true) {
          const { done, value } = await reader.read()
          if (done) break
          buffer += decoder.decode(value, { stream: true })
          const lines = buffer.split('\n\n')
          buffer = lines.pop() ?? ''
          for (const line of lines) {
            if (!line.startsWith('data: ')) continue
            const evt = JSON.parse(line.slice(6)) as Event
            if (evt.type === 'partial') setText((t) => t + evt.text)
            else if (evt.type === 'error') {
              setError(evt.message)
              setStatus('error')
            }
          }
        }
        setStatus('done')
      })
      .catch((err) => {
        if (err.name === 'AbortError') return
        setError(err.message)
        setStatus('error')
      })

    return () => controller.abort()
  }, [url, body])

  return { text, status, error, cancel }
}

Outcomes

  • SSE contract shipped with average time-to-first-token of 420ms.
  • Analysts adopted within the first month, replacing a manual SQL workflow.
  • Embedded Superset eliminated tab-switching to look up the cited chart.
  • Structured output removed the manual parsing step analysts used to do by hand.
  • Primitives library reused across three internal chat surfaces.

What I would do differently

  • Bake telemetry into the SSE contract from day one. We added it later and lost a week.
  • Push for an internal eval harness before launch, not after compliance asks for one.

Stack

React 18Redux ToolkitTypeScriptSSEApache SupersetTailwindNode.jsVercel AI SDK

Next case study

OneDATA.Plus

A 10K-node customer network graph that marketing teams actually use to pick outbound targets.