SShortSingh.
Back to feed

Why a Typeahead Trie Should Store the Top 10 Completions at Every Node

0
·7 views

A system design interview question about search autocomplete asks what a service does when a user types a single character. The naive approach of collecting and sorting every query under a prefix's subtree on each keystroke is correct but too slow at scale. Latency limits of about 0.1 seconds, including network time, make precomputation necessary. Illustrative capacity estimates show reads vastly outnumber writes and that client-side debouncing and caching can cut request volume roughly fourfold. The recommended fix is to precompute the top 10 completions at every trie node during build time, so each lookup only walks the prefix and returns a ready list.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Node.js File Exports Using Short-Lived Presigned Download Links

The article recommends authorizing each export request in the application, then returning a short-lived, object-specific presigned URL so large files bypass the app's servers. Such a link acts as a bearer credential, so it should be handled like a password that expires on a fixed schedule. Exports move through states such as queued, ready, expired, and revoked, and downloads are allowed only for ready records whose deadlines have not passed. Object keys are generated server-side from opaque IDs to avoid authorization flaws in path handling. The approach fits completed, non-sensitive results, but data needing instant revocation or per-viewer watermarking requires a more controlled delivery layer.

0
ProgrammingDEV Community ·

Generic Sensor Names Create Costly Maintenance Problems, Experts Say

Sensors left with default names like 'Contact 23' make it hard for technicians to match a device on a dashboard to its physical location during maintenance. This retrieval gap leads to wasted site visits, hard-to-audit automations, and battery replacements sent to the wrong unit. The article recommends a simple positional naming scheme of room, object, and role, applied at pairing time on site. It also advises keeping a one-page per-property device table with names, locations, models, and quirks, along with physical tags on each device.

0
ProgrammingDEV Community ·

Maestro, chat AI osFoundry yang menampilkan setiap langkah kerjanya

Maestro adalah ruang kerja AI dengan tool lengkap di aplikasi desktop osFoundry, yang dapat bekerja di dalam folder pengguna di komputer. Setiap jawaban disertai jejak kerja berupa daftar file, pencarian, file yang dibaca atau diedit, dan perintah terminal, yang masing-masing dapat dibuka untuk melihat detailnya. Mode Plan memungkinkan pengguna meninjau rencana sebelum agen mengubah apa pun, dan selama mode ini aktif aplikasi memblokir tool penulisan. Pengguna dapat menyetujui atau membatalkan rencana, sehingga perubahan hanya diterapkan setelah disetujui.

0
ProgrammingDEV Community ·

Codex CLI's queue command sends messages to running or unloaded sessions from another shell

Codex CLI 0.149.0 introduced a command that lets users send messages to existing local or remote sessions from outside the session. Version 0.166.0, released October 29, added a --resume flag so messages can also wake sessions that are not currently loaded. Sessions can be targeted by an exact name, set with the /rename command inside the terminal interface, or by UUID, which is safer for unattended scripts. Queued messages use the session's existing model and accept text only, with no image attachments. The official documentation also notes that --resume requires a running local daemon or a remote server, and that a zero exit code does not guarantee the session actually resumed.