Here's 18 lines of SQL to save you a week of writing a data pipeline in Go.
WITH page_timings AS (
SELECT page_type
, event_timestamp_utc
, LEAD(event_timestamp_utc, 1)
OVER(PARTITION BY session_id
ORDER BY event_timestamp_utc)
AS next_pageview
FROM events
WHERE event_type = 'page_view'
)
SELECT page_type
, MEDIAN(
DATEDIFF(sec,
event_timestamp_utc,
next_pageview)
) AS median_sec_on_page
FROM page_timings
GROUP BY page_type
;