InterviewDB Question

Article System OOD - Design a News Article Management Service

Question Details

Problem

Design a class hierarchy for an article management system. Support the following operations:

  • publish(article_id, title, body, author_id, tags) - store and index the article.
  • get(article_id) -> Article - retrieve by ID.
  • search(query) -> List[Article] - full-text search across title and body.
  • by_tag(tag) -> List[Article] -

return all articles with the given tag, sorted by publish time descending.
- by_author(author_id) -> List[Article] - all articles by that author.

python
class Article:
    id: str
    title: str
    body: str
    author_id: str
    tags: List[str]
    published_at: datetime

class ArticleSystem:
    def publish(self, title: str, body: str, author_id: str, tags: List[str]) -> Article: ...
    def get(self, article_id: str) -> Article: ...
    def search(self, query: str) -> List[Article]: ...
    def by_tag(self, tag: str) -> List[Article]: ...
    def by_author(self, author_id: str) -> List[Article]: ...

Follow-ups

  1. How would you implement search efficiently at scale - what index structure?
  2. How do you handle concurrent publish calls without duplicate IDs?
  3. Add a draft state so articles are not searchable until explicitly published.
  4. How would you paginate by_tag results?

Full Details

Problem

Design a class hierarchy for an article management system. Support the following operations:

  • publish(article_id, title, body, author_id, tags) - store and index the article.
  • get(article_id) -> Article - retrieve by ID.
  • search(query) -> List[Article] - full-text search across title and body.
  • by_tag(tag) -> List[Article] -

return all articles with the given tag, sorted by publish time descending.
- by_author(author_id) -> List[Article] - all articles by that author.

python
class Article:
    id: str
    title: str
    body: str
    author_id: str
    tags: List[str]
    published_at: datetime

class ArticleSystem:
    def publish(self, title: str, body: str, author_id: str, tags: List[str]) -> Article: ...
    def get(self, article_id: str) -> Article: ...
    def search(self, query: str) -> List[Article]: ...
    def by_tag(self, tag: str) -> List[Article]: ...
    def by_author(self, author_id: str) -> List[Article]: ...

Follow-ups

  1. How would you implement search efficiently at scale - what index structure?
  2. How do you handle concurrent publish calls without duplicate IDs?
  3. Add a draft state so articles are not searchable until explicitly published.
  4. How would you paginate by_tag results?
Free preview. Unlock all questions →

Topics

Coding Onsite Phone