# Low Level Design: Bookmark Service

Source: https://www.techinterview.org/post/3233471003/lld-bookmark-service/
Updated: 2026-04-18 · techinterview.org

## Bookmark Service: Core Schema

The bookmark service persists saved URLs with rich metadata and organizational structure.

### Bookmark Table


```
id            BIGSERIAL PRIMARY KEY
user_id       BIGINT NOT NULL
url           TEXT NOT NULL
title         TEXT
description   TEXT
favicon_url   TEXT
tags          JSONB          -- array of tag strings
collection_id BIGINT NULL    -- FK to Collection
is_public     BOOL DEFAULT false
created_at    TIMESTAMPTZ DEFAULT now()

UNIQUE (user_id, url)        -- per-user URL deduplication
```


### Collection Table


```
id         BIGSERIAL PRIMARY KEY
user_id    BIGINT NOT NULL
name       TEXT NOT NULL
is_public  BOOL DEFAULT false
created_at TIMESTAMPTZ DEFAULT now()
```


## Indexing Strategy

### Tag Index

Tags are stored as a JSONB array. A GIN index enables efficient tag-based filtering without normalizing tags into a separate table.


```
CREATE INDEX idx_bookmarks_tags ON bookmarks USING GIN (tags);
-- Query: SELECT * FROM bookmarks WHERE tags @> '["javascript"]';
```


### Full-Text Search

A GIN index on a generated tsvector column covering title and description enables fast keyword search across all bookmarks for a user.


```
ALTER TABLE bookmarks ADD COLUMN fts tsvector
    GENERATED ALWAYS AS (
        to_tsvector('english', coalesce(title,'') || ' ' || coalesce(description,''))
    ) STORED;
CREATE INDEX idx_bookmarks_fts ON bookmarks USING GIN (fts);
-- Query: WHERE fts @@ plainto_tsquery('english', 'input query')
```


## URL Deduplication

The UNIQUE constraint on `(user_id, url)` prevents a user from saving the same URL twice. On conflict, the application can offer to update the existing bookmark instead of inserting a duplicate.


```
INSERT INTO bookmarks (user_id, url, title, ...)
VALUES ($1, $2, $3, ...)
ON CONFLICT (user_id, url) DO UPDATE SET title = EXCLUDED.title;
```


## Metadata Extraction

After a user saves a URL, an async worker fetches the page and extracts metadata without blocking the save response.

- **Title:** `og:title` meta tag, fallback to `<title>`

- **Description:** `og:description`, fallback to `meta[name=description]`

- **Favicon:** `link[rel=icon]` or `/favicon.ico`


```
Worker flow:
1. Dequeue bookmark_id from extraction queue
2. HTTP GET url (with timeout + user-agent)
3. Parse HTML → extract og:title, og:description, link[rel=icon]
4. UPDATE bookmarks SET title=..., description=..., favicon_url=... WHERE id=bookmark_id
```


## Import and Export

### Import: Netscape Bookmark Format

Browsers export bookmarks as an HTML file in Netscape Bookmark Format. The importer parses `<A>` tags and batch-inserts records, skipping duplicates via ON CONFLICT.


```
Parse: <DT><A HREF="url" ADD_DATE="ts">Title</A>
Batch INSERT with ON CONFLICT (user_id, url) DO NOTHING
Enqueue metadata extraction for each new bookmark
```


### Export: Netscape Bookmark Format

Generate a standards-compliant HTML file browsers can import directly.


```
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
    <DT><A HREF="{url}" ADD_DATE="{unix_ts}">{title}</A>
</DL><p>
```


## Public Bookmarks and Social Sharing

When `is_public=true`, the bookmark is accessible via a public URL without authentication. Public collections are similarly accessible. Shareable links use the pattern `/u/{username}/b/{bookmark_id}`. Open Graph meta tags on the public page enable rich previews when shared on social platforms.

## Cross-Device Sync

Each bookmark carries a `last_updated_at` timestamp. Mobile clients store the timestamp of their last sync and request only changed items.


```
-- Server endpoint: GET /api/bookmarks?since=2024-01-01T00:00:00Z
SELECT * FROM bookmarks
WHERE user_id = $1 AND last_updated_at > $2
ORDER BY last_updated_at ASC
LIMIT 500;
```

Deleted bookmarks are soft-deleted (`deleted_at` timestamp) so clients can remove them locally. Hard deletion runs after all clients have synced past the deletion timestamp.

See also: [Netflix Interview Guide 2026: Streaming Architecture, Recommendation Systems, and Engineering Excellence](https://www.techinterview.org/post/3233460274/netflix-interview-guide-2026-streaming-architecture-recommendation-systems-and-engineering-excellence/)

See also: [Apple Interview Guide 2026: iOS Systems, Hardware-Software Integration, and iCloud Architecture](https://www.techinterview.org/post/3233460277/apple-interview-guide-2026-ios-systems-hardware-software-integration-and-icloud-architecture/)

See also: [Atlassian Interview Guide](https://www.techinterview.org/post/3233459919/atlassian-interview/)

See also: [Scale AI Interview Guide 2026: Data Infrastructure, RLHF Pipelines, and ML Engineering](https://www.techinterview.org/post/3233460275/scale-ai-interview-guide-2026-data-infrastructure-rlhf-pipelines-and-ml-engineering/)
