Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.
Answer: Design the frontend architecture for a high-performance, infinite scrolling social News Feed displaying rich media posts (text, images, video), post creation, real-time engagement reactions, and smooth $60\text{ FPS}$ scrolling.
graph TD
subgraph News Feed Frontend Architecture
Header[Feed Header: 10 New Posts Pill] --> Composer[Post Composer: Optimistic Post]
Composer --> VirtualList[Virtualized Feed List: Windowing]
VirtualList --> TopSpacer[Top Spacer: Height = measuredHeight]
VirtualList --> Card[Visible Feed Cards: 5-8 Active DOM Nodes]
VirtualList --> BottomSpacer[Bottom Spacer: Height = measuredHeight]
Card --> Media[Media Container: IntersectionObserver Video Autoplay]
Card --> Actions[Action Bar: Optimistic Like with Rollback]
VirtualList --> IO[Bottom Intersection Sentinel: Fetch Next Page]
end
IntersectionObserver; pause immediately when scrolled away.<FeedContainer>
├── <NewPostsFloatingBanner> ("10 New Posts" - Scrolls to top on click)
├── <PostComposer> (Rich text draft, image uploader, optimistic dispatch)
├── <VirtualizedFeedList>
│ ├── <TopPhantomSpacer style={{ height: topPadding }} />
│ ├── <FeedCard key={postId}>
│ │ ├── <PostHeader> (Avatar, author name, timestamp, menu)
│ │ ├── <PostContent> (Expandable text with "See more")
│ │ ├── <PostMediaGallery> (Responsive grid / video player)
│ │ └── <PostActionBar> (Like button, Comment count, Share)
│ ├── <BottomPhantomSpacer style={{ height: bottomPadding }} />
│ └── <InfiniteScrollSentinel /> (Observed by IntersectionObserver)
└── <FeedLoadingSkeleton />
Maintain a normalized state store (Zustand / Redux) to prevent duplicate data across components:
interface NormalizedFeedState {
entities: {
posts: Record<string, PostEntity>;
users: Record<string, UserEntity>;
comments: Record<string, CommentEntity>;
};
feed: {
postIds: string[];
cursor: string | null;
hasMore: boolean;
isFetchingNextPage: boolean;
newPostCount: number;
};
}
interface PostEntity {
id: string;
authorId: string;
createdAt: string;
content: string;
media: Array<{ type: 'image' | 'video'; url: string; aspectRatio: number }>;
likeCount: number;
isLikedByMe: boolean;
commentCount: number;
}
GET /api/v1/feed?cursor={cursor}&limit=10 $\to$ Returns { posts: PostEntity[], nextCursor: string | null, hasMore: boolean }POST /api/v1/posts $\to$ Payload { content: string, mediaIds: string[] }POST /api/v1/posts/{id}/like $\to$ Toggles like state with idempotency.ResizeObserver and store in an in-memory prefix-sum array to compute exact top/bottom padding offsets in $O(\log N)$ time.const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
const video = entry.target as HTMLVideoElement;
if (entry.isIntersecting && entry.intersectionRatio >= 0.5) {
video.play().catch(() => {});
} else {
video.pause();
}
});
},
{ threshold: 0.5 }
);
isLikedByMe = true and increment likeCount += 1.newPostCount in a floating pill button ("10 new posts $\uparrow$") and prepend only when clicked.Answer: Design a search and booking platform coordinating responsive filter bars, date-range calendar pickers, virtualized property listings, and interactive map pin clustering.
ne_lat, sw_lng) are serialized directly into URL query parameters for shareability and browser back-button support.Answer: Design a lightweight, responsive web ride-booking application supporting real-time GPS vehicle tracking, pickup point selection, route polyline animation, and surge pricing alerts.
Answer: Design an ultra-lightweight Progressive Web App (PWA) operating under unstable 2G/3G network connections with minimal data consumption and near-instant load times.
import(), lightweight UI primitives, and zero heavy external libraries.workbox-precaching) to ensure instant $0\text{ms}$ cold starts.navigator.onLine === true.Answer: Design a custom HTML5 video player supporting Media Source Extensions (MSE), adaptive bitrate streaming (HLS / DASH), buffer starvation management, and interactive scrubber previews.
.m4s video/audio chunks over HTTP and append directly into the browser's SourceBuffer.background-position on a tooltip lens.You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.
One-time settlement () · Lifetime access · Zero subscription