1. Let's build Uber again

Table of contents

Overview

For the past couple of weeks, I have been exploring various systems in the tech domain, and what caught my attention were the social media platforms. I started delving deeper into them and discovered the concept of distributed systems. That's when I had the idea to build my own system to truly understand these concepts. I decided to create something similar to a ride-sharing app because I believed it would be a comparatively easier way to get started.

I am aware that this project won't be easy, but I am determined to give it a shot. I will be building everything from scratch. There are numerous new things I will be learning along the way, and I plan to document my progress through a series of blogs. So, if you're interested in learning and following my journey, please stay connected.

Disclaimer: As of writing this blog, I don't have a fully fleshed-out plan. I only have a rough idea of what I'm going to build, and the plan will definitely be updated. If at any point you feel that I'm making mistakes, if there are better ways to approach things, or if you have any suggestions, please feel free to share them in the comments below. I would greatly appreciate it.

Before I begin, there's one more thing I'd like to mention. I will make an effort to utilize available free resources as much as possible throughout the development of this project.

Let's Begin...

I have a high-level plan in mind, which includes the following components:

  1. A frontend to cater to user interactions.

  2. A database to store information about users, drivers, locations, etc.

  3. A backend to handle events such as customer ride bookings, vehicle location updates, new customer registrations, and more.

At the moment, I plan to temporarily host my APIs on render.com. Regarding the backend, I have knowledge of two programming languages: Golang and Node.js. After conducting some research, I concluded that Golang would be a suitable choice for this project due to its performance, scalability, and most importantly, its concurrency capabilities.

Let's proceed with installing Golang on the system. You can download it from the official website, choosing the appropriate version for your operating system. The installation and setup process is quite similar to that of other software, so I won't cover it here.

Now, let's begin building our first server. Create a file called server.go and add the following code to it.

package main

import (
    "fmt"
    "net/http"
)

func getData(w http.ResponseWriter, req *http.Request) {
  fmt.Fprintf(w, "Hey Riders!\n")
}
func main() {
    http.HandleFunc("/data", getData)

    err:= http.ListenAndServe(":8080", nil)
    if err != nil {
        fmt.Println("Error", err)
    }
}

Here, we are utilizing the http module to construct our first API endpoint. In this case, our getData() function takes two arguments: the first being http.ResponseWriter and the second being http.Request. Instead of passing the http.Request object as an object, we pass it as a pointer. This is because http.Request is a struct type, and passing it by value would create a copy of the struct, which might be unnecessary and inefficient, especially when dealing with large objects. The response generated by the getData() function is printed using the Fprintf method from the fmt module.

To proceed, open a terminal in the same folder where server.go is located and execute the following command to start the server.

go run server.go

This command will initiate a localhost server on port 5000. By visiting localhost:5000 in your web browser, you will see the message 'Hey Riders!' displayed. Alternatively, you can utilize the curl command to view the result directly in the terminal.

curl http://localhost:5000        //(o/p - Hey Riders!)

Congratulations! We have successfully built our first server using Golang. In the next set of upcoming blogs, we will explore hosting our code on render.com and delve into utilizing GitHub Actions for the continuous integration/continuous delivery (CI/CD) process.

Thank you for reading until the very end. Don't forget to subscribe to the newsletter to stay updated on the upcoming blogs. Feel free to share any suggestions or ideas in the comments section.