Quick revision
The short answer
Before any code, I would raise the legal and ethical question: whether each retailer's terms, robots rules and data rights allow this, and whether an official feed or API exists instead. Then the design issues: extraction rules per site kept as configuration and tested against saved pages because markup changes often, quality monitoring with alerts per site, a headless browser for pages that render with JavaScript (which jsoup cannot do and which changes the cost), and polite, isolated fetching with queues, per-domain limits and caching.
What to remember
In this answer, we saw that a price extraction service starts with permission: terms of service, robots rules and data rights, and a preference for official feeds or APIs. The design then keeps per-site extraction rules as configuration tested on saved pages, separates polite, isolated fetching with per-domain limits and caching from extraction, treats JavaScript-rendered sites as a separate, expensive class that needs a headless browser, and monitors quality per site so silent breaks are caught before wrong data reaches users.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Before any code, I would raise the legal and ethical question: whether each retailer's terms, robots rules and data rights allow this, and whether an official feed or API exists instead. Then the design issues: extraction rules per site kept as configuration and tested against saved pages because markup changes often, quality monitoring with alerts per site, a headless browser for pages that render with JavaScript (which jsoup cannot do and which changes the cost), and polite, isolated fetching with queues, per-domain limits and caching.
Why this question is asked
Product teams often see scraping as a quick way to get competitor prices or availability. Engineers who have run such a system know that the parsing is the easy part and everything around it is hard: permission, change, quality and cost. Interviewers ask this design question to senior candidates to see whether they raise those issues before writing a single selector. In this answer, we will start with the questions that decide whether we should build it at all, then design the extraction rules, the fetching layer, the handling of JavaScript pages, and the monitoring that tells us when a site has silently broken.
1First: May We Do This at All?
Scraping thousands of retailer pages is a legal and reputational decision before it is a technical one. Each site's terms of service may forbid automated access or reuse of its data. Its robots.txt file says which paths automated clients should avoid. Prices and descriptions may be covered by database rights or copyright in some countries, and personal data such as reviewer names brings privacy law with it. So the first issue I raise is a review with legal for each class of site, and a clear record of what we are allowed to collect and keep.
The second question is whether we need to scrape at all. Many retailers offer product feeds, affiliate APIs or data partnerships, and price comparison services usually work from such feeds. A feed is structured, stable and given with permission, so it is cheaper and safer than any scraper. The design should treat scraping as the fallback for sites without a feed, not the default.
2Extraction Rules as Configuration, Tested on Saved Pages
jsoup lets us pick fields out of HTML with CSS selectors. The trap is to hard-code a Java class per retailer. Retailers redesign their pages several times a year, so with thousands of sites some rules break every day, and each break would need a code change and a deployment. Instead, the rules for each site live as configuration: a selector for each field, plus small normalisation steps such as parsing a price string.
Many retailers also embed structured data for search engines, such as JSON-LD blocks with the schema.org Product type. Where it exists, reading it is far more stable than reading the visual markup, so the extractor should try structured data first and fall back to selectors.
Every rule set is tested against saved copies of real pages. When a site is onboarded, we store a few sample pages and the expected values, and the test suite runs every rule against its samples. When a rule breaks in production, the fix comes with a new saved page, so the same break is tested forever. This keeps rule changes safe for people who are not Java developers, such as a data operations team.
3Fetching Politely and in Isolation
Fetching is separated from parsing. A scheduler puts URLs on a queue, fetch workers download pages, store the raw HTML with its fetch time, and put a message on a second queue for the extractors. This separation lets us re-run extraction on stored pages when a rule is fixed, without fetching again.
Politeness is a design requirement, not an afterthought. Each domain gets a concurrency limit, for example one request at a time and a few seconds between requests, enforced by the scheduler no matter how many workers we run. We honour robots rules and identify our client honestly with a user agent and contact address. We cache responses and use conditional requests with ETag or Last-Modified headers so unchanged pages cost little. And the fetchers run in their own network zone with their own egress addresses, so a site blocking us never affects our main product, and a malicious page cannot reach internal systems.
- Schedulerwhich URLs are due, per-domain rate limits, robots rules
- Fetch workersisolated network zone, caching, conditional requests
- Raw page storeHTML with fetch time, kept for re-extraction and tests
- Extractorsjsoup plus per-site rules; headless browser only where needed
- Validation and quality metricsrequired fields, plausible values, per-site success rate
- Product data store and APIwhat the product team consumes
6 layers, from the top down. Step through them one at a time.
Fetching, extraction and quality checks are separate stages so each can be retried and scaled on its own.
4Pages Rendered by JavaScript
jsoup parses the HTML the server sends. It does not run JavaScript. Many modern retailer sites send an almost empty page and build the product details in the browser with scripts. For those sites, jsoup sees no price at all. The options are to find the JSON API the page itself calls, which is often easier to read but raises the same permission questions, or to render the page in a headless browser, a real browser engine without a screen, driven by a tool such as Playwright.
This choice changes the cost by an order of magnitude. A jsoup fetch and parse costs a few milliseconds of CPU and a few megabytes of memory. A headless browser page load can take seconds and hundreds of megabytes. If 20 percent of 50,000 pages need rendering, that is 10,000 browser sessions per cycle, which needs its own worker pool and budget. So the design classifies each site as static or rendered, and product should know which sites are expensive before promising coverage.
5Monitoring Extraction Quality per Site
Scrapers rarely fail loudly. When a site changes its markup, the fetch still succeeds with status 200, and the extractor simply finds no price, or worse, finds the wrong element and returns the shipping cost as the price. So we measure quality, not just errors. For each site we track the share of pages where each required field was found, and we validate values: a price must parse, be positive, and not jump by 90 percent overnight on most products at once.
Alerts fire per site when a metric drops sharply, for example the price success rate for one retailer falls from 98 percent to 5 percent in an hour. The alert goes to the team that owns the rules, with a link to a sample page, and the affected site's data is marked stale instead of serving wrong values. Downstream consumers must see how fresh each value is, because a price that was correct three days ago may be wrong today.
6Follow-up questions
Why not let an AI model read the pages instead of selectors?
It can help, for example to suggest selectors when a site changes or to handle long-tail sites, but it costs far more per page than a selector, it can produce plausible wrong values, and it does not remove the legal questions. A common design uses selectors and structured data for the bulk and a model only for repairs or rare cases, with the same quality checks on its output.
How do you handle a retailer that blocks you?
We stop and respect it. A block is a clear signal that the site does not want automated access, and working around it with rotating addresses or disguised clients creates legal and reputational risk. The right next step is a conversation about a feed or partnership, and product decides whether that site is worth it.
How often should pages be fetched?
Based on how fast the data changes and how much it matters. Prices on popular products may need daily checks, while titles rarely change. A scheduler with per-site and per-product intervals, plus conditional requests, keeps the load on each retailer as low as the product need allows.
7Conclusion
In this answer, we saw that a price extraction service starts with permission: terms of service, robots rules and data rights, and a preference for official feeds or APIs. The design then keeps per-site extraction rules as configuration tested on saved pages, separates polite, isolated fetching with per-domain limits and caching from extraction, treats JavaScript-rendered sites as a separate, expensive class that needs a headless browser, and monitors quality per site so silent breaks are caught before wrong data reaches users.
Open with
The first thing I would raise is not technical: do we have the right to do this? I would want a legal review of retailers' terms, robots rules and data rights, and I would push for official product feeds, affiliate APIs or partnerships first, using scraping only as a fallback.
Then, if they want more
If we go ahead, I would separate the system into stages: a scheduler with per-domain rate limits and robots handling, isolated fetch workers with caching and conditional requests that store raw pages, extractors, and a validation step.
Extraction rules per site would be configuration, selectors and normalisation steps, not Java classes, because markup changes all the time; I would prefer schema.org structured data where sites provide it, and test every rule against saved real pages. jsoup cannot run JavaScript, so sites that render in the browser need a headless browser like Playwright, which costs seconds and hundreds of megabytes per page, so product should know which sites are expensive.
Finally, I would monitor quality per site, field success rates and plausibility of values, with alerts when a site drops sharply and stale data marked as stale, because scrapers fail silently with a 200 response.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Product wants a service that extracts structured data (title, price, availability) from...": https://scrivio-interview-library.netlify.app/java/xml-processing/42be31a4d7/