Design a dashboard for Restaurants
Difficulty: EASYCategory: LLDFrequency: 1Asked On 2025-03-26
Problem Statement
Design a Restaurant Dashboard System that enables restaurants to monitor and track key business metrics in real-time. The system should support the following core functionalities:
1.Show Number of Orders Placed
2.Display the total count of orders placed across a configurable time window (e.g., daily, weekly, or monthly).
3.Show Top 3 Dishes Ordered
4.Display the top 3 most frequently ordered dishes based on the number of times each dish has been ordered.
5.Show Total Sales Amount
6.Calculate and display the total revenue generated from orders placed, again over a configurable time window.
📈 Assumptions & Scale Requirements
•The system should support:
•10,000 restaurants
•100,000 orders placed per second
•Each order may contain multiple dishes.
•Each restaurant has its own menu.
•Dishes have static prices (price doesn’t vary per order).
•The dashboard can tolerate a slight delay (eventual consistency is acceptable).
•Dashboard queries should be fast and efficient for real-time usage.
.
Solution
🧱 Key Concepts
•Restaurant – has its own dishes and receives orders.
•Dish – an item in the restaurant's menu.
•Order – contains one or more ordered dishes.
•Dashboard – aggregates and presents metrics based on orders.
🧩 Class Design
1. Restaurant
1java
2CopyEdit
3class Restaurant {
4 String restaurantId;
5 String name;
6 List<Dish> menu;
7 List<Order> orders;
8
9 void addDish(Dish dish);
10 void placeOrder(Order order);
11 Dashboard getDashboard(LocalDate start, LocalDate end);
12}2. Dish
1java
2CopyEdit
3class Dish {
4 String dishId;
5 String name;
6 double price;
7}3. Order
1java
2CopyEdit
3class Order {
4 String orderId;
5 LocalDateTime timestamp;
6 List<OrderItem> items;
7
8 double getTotalAmount();
9}4. OrderItem
1java
2CopyEdit
3class OrderItem {
4 Dish dish;
5 int quantity;
6}5. Dashboard
1java
2CopyEdit
3class Dashboard {
4 int totalOrders;
5 List<DishStats> topDishes;
6 double totalSales;
7}
8
9class DishStats {
10 String dishName;
11 int timesOrdered;
12}🔁 Flow of Actions
1.Place Order:
•Restaurant creates an Order.
•Order contains OrderItems with references to Dish.
•Order is added to the orders list of the restaurant.
2.Generate Dashboard:
•Filter orders within date range.
•Count total orders.
•Aggregate dish quantities and total sales.
•Return Dashboard object.
📌 Example Logic (Java-like Pseudocode)
Restaurant.getDashboard(start, end)
1java
2CopyEdit
3Dashboard getDashboard(LocalDate start, LocalDate end) {
4 List<Order> filteredOrders = orders.stream()
5 .filter(o -> !o.timestamp.toLocalDate().isBefore(start) && !o.timestamp.toLocalDate().isAfter(end))
6 .collect(Collectors.toList());
7
8 int totalOrders = filteredOrders.size();
9 Map<String, Integer> dishCount = new HashMap<>();
10 double totalSales = 0;
11
12 for (Order order : filteredOrders) {
13 totalSales += order.getTotalAmount();
14 for (OrderItem item : order.items) {
15 dishCount.put(item.dish.name, dishCount.getOrDefault(item.dish.name, 0) + item.quantity);
16 }
17 }
18
19 List<DishStats> topDishes = dishCount.entrySet().stream()
20 .sorted((a, b) -> b.getValue() - a.getValue())
21 .limit(3)
22 .map(e -> new DishStats(e.getKey(), e.getValue()))
23 .collect(Collectors.toList());
24
25 return new Dashboard(totalOrders, topDishes, totalSales);
26}✅ Extensibility
•Add support for different order types (dine-in, delivery).
•Plug in a caching layer or database.
•Add time filters (last 7 days, today, etc.)
•Paginate or aggregate for high-volume restaurants.