URL shortener & link analytics database schema

The classic system-design question, modelled properly: short codes from a base62 counter, custom aliases and custom domains, an append-only click log with daily rollups, expiry and click limits, QR codes and blocked-domain safety checks.

Url Shortener ER diagram

URL shortener & link analytics database schema n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 n1 users idBIGINT emailVARCHAR display_nameVARCHAR password_hashVARCHAR api_token_hashVARCHAR is_suspendedBOOLEAN created_atTIMESTAMPTZ workspaces idBIGINT nameVARCHAR slugVARCHAR owner_idBIGINT plan_tierVARCHAR monthly_link_quotaINTEGER created_atTIMESTAMPTZ workspace_members workspace_idBIGINT user_idBIGINT roleVARCHAR invited_by_idBIGINT joined_atTIMESTAMPTZ domains idBIGINT workspace_idBIGINT hostnameVARCHAR is_defaultBOOLEAN verification_tokenVARCHAR verified_atTIMESTAMPTZ ssl_statusVARCHAR created_atTIMESTAMPTZ code_blocks idBIGINT instance_idVARCHAR range_startBIGINT range_endBIGINT next_valueBIGINT exhausted_atTIMESTAMPTZ claimed_atTIMESTAMPTZ links idBIGINT workspace_idBIGINT domain_idBIGINT short_codeVARCHAR code_valueBIGINT destination_urlTEXT titleVARCHAR created_by_idBIGINT is_custom_aliasBOOLEAN redirect_statusSMALLINT password_hashVARCHAR expires_atTIMESTAMPTZ max_clicksINTEGER click_countBIGINT last_clicked_atTIMESTAMPTZ is_disabledBOOLEAN deleted_atTIMESTAMPTZ created_atTIMESTAMPTZ link_tags link_idBIGINT tagVARCHAR created_atTIMESTAMPTZ click_events idBIGSERIAL link_idBIGINT occurred_atTIMESTAMPTZ ip_hashVARCHAR country_codeCHAR cityVARCHAR refererTEXT user_agentTEXT device_typeVARCHAR browserVARCHAR osVARCHAR is_botBOOLEAN click_daily link_idBIGINT dayDATE country_codeCHAR clicksINTEGER unique_visitorsINTEGER bot_clicksINTEGER computed_atTIMESTAMPTZ qr_codes idBIGINT link_idBIGINT image_formatVARCHAR error_correctionCHAR foreground_colorVARCHAR background_colorVARCHAR logo_urlTEXT scan_countBIGINT created_atTIMESTAMPTZ blocked_domains idBIGINT hostnameVARCHAR reasonVARCHAR sourceVARCHAR match_subdomainsBOOLEAN expires_atTIMESTAMPTZ created_atTIMESTAMPTZ safety_scans idBIGINT link_idBIGINT verdictVARCHAR providerVARCHAR final_urlTEXT detailsJSONB scanned_atTIMESTAMPTZ

Related database schemas