Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • System Design Tutorial
  • What is System Design
  • System Design Life Cycle
  • High Level Design HLD
  • Low Level Design LLD
  • Design Patterns
  • UML Diagrams
  • System Design Interview Guide
  • Scalability
  • Databases
Open In App
Next Article:
Design City Guide System like Foursquare
Next article icon

Design City Guide System like Foursquare

Last Updated : 05 Dec, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report
PURPOSE OF CITY GUIDE SERVICE City guide will be the service that allows users to search and find place near to user's location. You can think this service will be similar to Foursquare. Before starting to design system, it will be nice to define the purpose of system. Meaning that, before designing process, requirements should be clear and well-defined. The purpose of city guide service is to presenting locations to users based on their locations. You can find any places such as restaurants, theaters, cinemas and more. Suggestions will start from nearby locations to far locations but system will also support to search places based on dedicated locations. REQUIREMENTS AND SYSTEM BOUNDARIES If you want to design a system, you must first define the requirements and system boundaries. Before starting to design, you will have Service Design Document and you will define all the requirements from scratch. Since the purpose of city guide service is to create well-architected city guide service, it must be able to recommend places based on your searching query and location. So our system will support these features;    - Users must be able to create an account.    - Users must be able to login the system.    - Users must be able to logout from the system.    - Users must be able to search places such as a restaurant, theatre, cafe, cinema and more when they login or logout.    - Users must be able to add comments to places if they login.    - Users must be able to like or dislike places.    - Users must be able to add a new place and system admin should review it.    - Users must be able to add pictures to places.    - Users must be able to update or delete places if they have a permission.    - System must be able to suggest places from most relevant to less relevant.    - System must be able to suggest places based on user's query and location.    - System must be able to suggest places based on popularity and user reviews.    - System must be able to monitor.    - System must be able to recommend new places by sending push notifications.    - System should be highly available.    - System should be highly reliable.    - System should be durable.    - System should be resilient.    - System should be highly cost and performance efficient. Basically system should support 5 important pillars these are;    - Availability    - Reliability    - Resiliency    - Durability    - Cost Performance These are the pillars that we should consider together since they are coupled to each other. In brief, availability means that system should be always available. Reliability means that system should work as expected. Resiliency means that how and when system will recover itself if there is any problem. Durability is the one pillar that each part of system should exists until we delete. Cost performance is also important topic that will basically related to use services under cost efficiency. It can be illustrated like if the system will be built on AWS and it is enough to use t2 micro EC2 instances, there will be no any reason to use larger EC2 instances and pay extra money. Notice that each system will grow day by day so systems will be more complex in the future (like after 5 years) but the important thing is if you have well-defined requirements and structure, there will be no too much work to add new components to your system. When system boundaries and functional requirements are defined, it is needed to think about cloud or on-promise options. Cloud services have a lot of advantages like cost efficiency, high speed performance, back-up solutions, maintenance, unlimited storage capacity and more.. Your system can be;    - %100 on-promise (Your own data center/server)    - %100 cloud (AWS, Google Cloud, Azure)    - Mix of on-promise and cloud (You can have both during the migration process) Capacity estimation will be important in the first place (especially for on-promise services) so you can estimate how many server count you need or how to separate your services and which database you will use? Also notice that, your system will be read-heavy and read traffic will be more than write traffic. Let's assume there will be 10 Million places in city guide system in 5 years and daily query counts will reach to 10.000. You can estimate that system will grow each year and you can estimate buffer. This means that you will keep 10 million places informations with their metadata and also pictures. If we assume average size of photo 25 KB and each place have average 5 picture; The capacity will be approximately equals to 10 Million * 5 * 25 KB + (User Metadata informations) + (Location Metadata informations). It is recommended to have replication and back-up solutions for data to prevent data loss so it will be approximately 3 times bigger than what we estimate. This calculation is just a brief example of how to define system capacity and we will not calculate daily download/upload capacity and metadata capacities but you should consider this calculation (and daily read/write capacity estimation) for service/database scaling. API ESTIMATION City guide service can support both REST or SOAP strategy. You can also think about GRPC this is a new strategy coming from Google and the biggest advantage of GRPC is to use smaller bandwidth and resource. If we continue with REST, there will be four main APIs to design the system.   - AddPlace(api_dev_key, name, description, longitude, latitude, category, pictures): This API returns HTTP response with newly added place's information. (202 accepted if success)   - DeletePlace(api_dev_key, placeID): It can return HTTP response 200 (OK) or 204 (No Content) based on your response.   - UpdatePlace(api_dev_key, updatePlaceRequest): updatePlaceRequest will have a placeID to know which place we are updating.   - GetPlace(search_query, userlocation, categoryfilter = null, sortby = 'distance || popularity', page = 1, distanceRadius = 5, maximum_return_count = 20): Return JSON with locations metadata. Results will be ordered based on user query and location. DESIGN AND DATABASE SCHEMA Saving the data will be distributed into 2 parts. The first one will be related to keep static content like location pictures. We can use S3 to keep static contents if we are building our service AWS and in front of S3, we can use Cloudfront as a CDN. Cloudfront will act as a cache and it will help system to return response fast. If you are building your system as an on-promise, then you need to have image storage. S3 is a AWS offer and it will help our system to keep static media contents in a secure way. For metadata (places, pictures, users) we can use SQL and NoSQL. NoSQL is the best way to scale system easily. On the other hand, if we think the relations and constraints of SQL, scaling SQL databases is very difficult.    - Place:ID, AddedBy, Name, Lat, Lng, Category, Description, AddedDate, LikeCount, DisLikeCount    - User:ID, UserName, Password, Email, RegisterDate, LastLoginDate    - Comment:ID, Like, DisLike, Comment, CommentDate    - UserPlaceComment:ID, CommentID, UserID, PlaceID 8 byte will be enough to keep placeID and userID. Additionally, we will keep longitude and latitude with 8 bytes. Data will be indexed based on placeID, lat and lng. We will send a query to place table based on place location and user location. So query will evaluate; (Places where placeLongitude between userLongitude - Radius and userLongitude + Radius and placeLatitude between userLatitude - Radius and userLatitude + Radius) This way is not the optimal way since we need to calculate both for latitude and longitude. We can use a grid to solve performance problems. We can divide the whole world into smaller grids. This ensures that we can only deal with the neighbour of grids. Thanks to this method, we just only focus on the user location grid and its neighbour grids. A map is the best choice to use a grid. Key is the gridID. Value is the whole places in this grid. So query will evaluate; (Places where Latitude between userLatitude - Radius and userLatitude + Radius and GridID in (neighbour grids) Note that of course we will have more database table and these are just sample. It will be nice to follow normalization rules for database designing process. Also we can partition the system based on;    - userID    - regionID    - locationID Using userID and regionID can create a distribution problem. Some regions may have more locations than others and in that case system will not be uniformly distributed. We can partition based on both locationID and regionID. SYSTEM DESIGN CONSIDERATION If we are designing a system, the basic concepts we need are;    - Client    - Services    - Web server    - Application server    - Media file Storage    - Database    - Caching    - Replication    - Redundancy    - Load balancing    - Sharding As we mentioned above, the replication process is a valuable process to provide high availability, high reliability, and real-time experience. Replication and back-up are two important concepts to provide pillars we mentioned before. Replication is a very important concept to handle a failure of services or servers. Replication can be applied database servers, web servers, application servers, media storages and etc.. Actually we can replicate all parts of the system. (Some of AWS services like Route53, they are highly available in itself so you do not need to take care of replication of Route53, Load balancer, etc..) Notice that replication also helps system to decrease response time. You imagine, if we divide incoming requests into more resources rather than one resource, the system can easily meet all incoming requests. Additionally, the optimum number of a replica to each resource is 3 or more. You can provide redundancy by keeping data in different Availability zone or different region in AWS. We can keep same data onto three different resources and thanks to this process if one server dies, the system automatically continues to work replicas. One more advantage of replication is the system may continue to run at an update to the system. In replication process, Master server will be responsible for writing and reading operations; and slaves are responsible for reading operations. Load balancing refers to distributing requests across a group of services and servers. When we have talked about the replication and sharding, an incoming request must be directed and this is done by a load balancer. We can use Round-Robin method to redirect incoming requests but there may be a problem in this case. Round-Robin stops sending requests to dead servers but Round-Robin cannot stop sending requests to a server exposed to heavy traffic. We can prepare intelligent Round-Robin algorithm to take away this problem. Additionally, we can use consistent hashing to redirect incoming requests. Consistent hashing ensures that system becomes more uniformly distributed. The possible problem for sharding with a load balancer is how we rebuilt the system when this system dies. The possible approach is brute-force. This method is slow because we need to rebuilt whole the system from the beginning. We can eliminate this problem by using reverse indexing approach. We can have another Index server that will hold all information about reverse indexing. Reverse index maps all places. We need to build a map and key is the serverID and value is all places. For caching strategies, we can use global caching mechanism by using cache servers. We can use Redis or memcache but the most important part of caching strategy is how to provide cache eviction. If we use global cache servers, we will guarantee that each user will see the same data in the cache but there will time latency if we use global cache servers. As a caching strategies, we can use LRU (Least Recently Used) algorithm. For media files caching, as we mentioned before, we will use CDN. CDN is located on different edge locations so that the response time will be smaller than fetching media contents directly from AWS S3. We can have various ranking mechanisms which are most popular, most relevant, newest and etc... As you know, we can have many servers and we need to get data from these servers. Because of this reason, we need to aggregate function to combine all these data to obtain the most desirable solution. BASIC CODING OF SYSTEM
Java
// Java Program to illustrate the Design public enum UserStatus{     LOGIN,     LOGOUT     ... }  public enum ReviewStatus {     LIKE,     DISLIKE }  public enum LocationStatus{     PUBLIC,     PRIVATE,     ... }  public enum LocationCategory {     EVENT,     EDUCATION,     FOOD,     HEALTH,     ENTERTAINTMENT,     .... }   public class AddressDetails {     private String street;     private String city;     private String country;     private double latitude;     private double longitude;     ... }  public class AccountDetails {     private Date createdTime;     private AccountStatus status;     private boolean updateAccountStatus(AccountStatus accountStatus);     ... }  public class Comment {     private Integer id;     private User addedBy;     private Date addedDate;     private String comment;      public boolean updateComment(String comment);     ... }  public class Location {       private Integer id;     private User createdBy;     private LocationCategory locationCategory;     private LocationStatus locationStatus;      private HashSet<Integer> pictures;     private HashSet<Integer> userLikes;     private HashSet<Integer> userDisLikes;     private HashSet<Integer> userComments;     ... }  public class User {     private UserStatus userStatus;     private Double latitude;     private Double longitude;     private AccountDetails accountDetails;     private UserRelations userRelations;      public List<User> searchLocation(query);     ... }  public LoginUser extends Users{     private int id;     private String password;     private String nickname;     private String email;          private boolean updatePassword();     public boolean addPlace(Place place);     public boolean updatePlace(Place place);     public boolean addComment(Integer placeID, String comment);     public boolean reviewPlace(Integer placeID, ReviewStatus status);     .... } 
Reference: https://developer.foursquare.com/docs/resources/

Next Article
Design City Guide System like Foursquare

O

ozanakay
Improve
Article Tags :
  • Misc
  • Design Pattern
  • System Design
Practice Tags :
  • Misc

Similar Reads

    Design Facebook | System Design
    Designing a system as complex and globally impactful as Facebook requires careful consideration of various factors, including scalability, reliability, and performance. This article explores the key components and architectural decisions involved in designing Facebook, focusing on its core functiona
    14 min read
    Design a Picture-Sharing System - System Design
    In the present day, the need for good tools to exchange and organize images has never been this much higher. As for social networking, e-shopping, personal branding, and many other related purposes, users anticipate that the sites they visit provide them with fast and dependable environments with or
    11 min read
    System Design - Design Google Calendar
    Google Calendar is like a special calendar that we can use on our computer or phone. We can use it to remember important things, like birthdays, appointments, and events. We can also set reminders to help us remember when something is coming up soon. We can also share our calendars with our family o
    8 min read
    Designing Google Maps | System Design
    A web mapping tool called Google Maps offers a range of geographic data, such as street maps, satellite photos, streets' aerial views, real-time traffic reports, and directions. There are several versions of it available, such as web, mobile, etc. In this article, we will see the system design of Go
    11 min read
    Cab Booking System - Low-Level Design
    A Cab Booking System is a service provider that allows users to book a ride from their computer or phone. Users can select the kind of cab they want, enter their pickup and destination, and request a ride. The system will then find a nearby available driver and send the driver to pick up the user. U
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences