top of page
sisodiaarpit

From Data Scientist to Full-Stack Developer: Mastering UI, APIs, and Docker for Scalable Solutions

I know R, Python, Tensorflow, Pytorch etc. I know enough of timeseries, clustering, classificaiton, RL, deep learning, diffusion models and what not. But these things are keep on changing faster than anything. What has become important to fit all this in end to end solution so here I have taken one example to put my ml code into end to end application with explanation of core technology/concepts. Here are the components-


  1. front end -Java Script

  2. backend- any python code with ml/llm model ( with fastapi ; a framework in python)

  3. docker file for front end and backend servers.

    I am planning to build simple regression backend code which runs on a server and UI ( as a service) send requests through end points.



 

A) Dynamic Applications:


Many application required both front end and backend servers esp which are dynamic /client server models-

  1. Dynamic Applications:

    • Applications like e-commerce websites, social media platforms, and online banking systems require:

      • Front End: For user interaction (e.g., forms, buttons, dashboards).

      • Back End: To handle data storage, authentication, and business logic.

  2. Client-Server Model:

    • When an application relies on a centralized server for data and processing, it typically requires both:

      • Front End: To present data to the user.

      • Back End: To process and serve the data.




 

B ) Another basic thing that comes in my mind is 'server'. I know this is a machine.


A server is a computer system or software application that provides services, resources, or data to other devices, known as clients, over a network. It acts as a central hub that processes requests from clients and delivers the appropriate responses.

Key Characteristics:

  1. Role: Servers can host websites, manage databases, handle email, run applications, or store files.

  2. Communication: Typically communicates over protocols like HTTP, FTP, or SMTP, depending on the type of service provided.

  3. Hardware or Software:

    • Hardware server: A physical machine designed for server functions, often with high-performance specifications.

    • Software server: A program or application that runs on hardware to provide specific services (e.g., Apache web server, SQL database server).

Types of Servers:

  1. Web Server: Delivers websites to clients via browsers.

  2. Database Server: Stores and manages access to databases.

  3. File Server: Provides file storage and sharing capabilities.

  4. Application Server: Runs specific applications for clients.

  5. Mail Server: Manages and stores email communications.

Proxy Server: Acts as an intermediary for requests between clients and other servers.


lets understand further with detailed example. When you perform a Google search, the client and server play distinct roles in enabling the interaction:

Client:

  • Definition: The client is your device (e.g., computer, smartphone, tablet) and the web browser (e.g., Chrome, Safari) you use to interact with the internet.

  • Role in Google Search:

    1. You open your browser and type a query into the Google search bar.

    2. The browser sends an HTTP request to Google's servers, containing the search query and other relevant data (like location and preferences).

Server:

  • Definition: The server is a powerful computer system hosted by Google that processes your request and delivers the required data.

  • Role in Google Search:

    1. The server receives your query and processes it by searching Google's vast index of web pages.

    2. It applies algorithms to rank the results based on relevance to your query.

    3. The server generates an HTTP response containing the search results and sends it back to the client (your browser).


Interaction Flow:

  1. Request: The client sends a search query to the server.

  2. Processing: The server processes the query, runs it through Google's search algorithms, and retrieves relevant results from its database.

  3. Response: The server sends the results back to the client in a format that the browser can display (HTML, CSS, JavaScript).




 

C) What should I know for front end? java script, node js, react what are these?


JavaScript is typically used alongside HTML and CSS in front-end development:

  • HTML: Provides the structure of the webpage.

  • CSS: Defines the style and layout of the page.

  • JavaScript: Adds interactivity and dynamic content.


It is used for backend also.

If you're using Node.js, you can write all your backend code in JavaScript (or TypeScript, which is a superset of JavaScript). There's no need to learn or use another language unless your project has specific requirements that JavaScript/Node.js cannot meet (which is rare).

Why JavaScript is Enough for the Backend:

  1. Comprehensive Ecosystem:

    • With Node.js and its extensive library ecosystem (via npm), you can perform almost any backend task, such as:

      • Handling HTTP requests (e.g., with Express.js).

      • Working with databases (e.g., MongoDB, MySQL, PostgreSQL).

      • Implementing authentication and authorization.

      • Building APIs and managing microservices.

  2. Real-Time Features:

    • Node.js excels at creating real-time applications (e.g., chat apps, live updates) using libraries like Socket.io.

  3. Scalability:

    • Its asynchronous, event-driven architecture makes it suitable for highly scalable and high-concurrency systems.

  4. Single Language:

    • You can use JavaScript for:

      • Frontend: Dynamic UI and client-side logic.

      • Backend: API endpoints, server-side logic, and database interactions.

  5. Community and Support:

    • Node.js has a massive developer community and active support, making it easier to find solutions to problems.

Situations Where Other Languages Might Be Needed:

  1. High-Performance Computing:

    • For CPU-intensive tasks (e.g., data processing, machine learning), languages like Python, C++, or Go may perform better.

  2. Legacy Systems:

    • If you're integrating with an existing system built in another language, you might need to interact with it.

  3. Specialized Use Cases:

    • Languages like Python are often used for data science and AI.

    • Java or C# might be preferred for enterprise applications with specific requirements.


React is a popular open-source front-end JavaScript library developed by Facebook, used for building user interfaces, especially for single-page applications (SPAs).




 

D) How Client and Server Communicate


The client-server communication is the process by which a client (e.g., a browser or an app) interacts with a server to exchange data and perform tasks. This communication typically occurs over the internet using a set of protocols and methods.

Steps in Client-Server Communication:

  1. Request:

    • The client sends a request to the server.

    • This request is usually made via the HTTP(S) protocol (HyperText Transfer Protocol), though other protocols (e.g., WebSocket, FTP) can also be used.

    • Example: Typing a URL in your browser generates an HTTP GET request.

  2. Processing:

    • The server receives the request, processes it (e.g., querying a database, executing logic), and prepares a response.

  3. Response:

    • The server sends back the processed data (e.g., HTML, JSON) to the client as an HTTP response.

  4. Rendering:

    • The client receives the response and displays the information to the user (e.g., rendering a web page or updating app content).

Protocols Used in Client-Server Communication:

  1. HTTP/HTTPS:

    • The primary protocol for web communication.

    • Example: A browser fetching a website.

  2. WebSocket:

    • Enables full-duplex communication for real-time updates.

    • Example: Live chat applications or stock price tickers.

  3. REST and GraphQL:

    • Common architectures for APIs that allow clients to interact with servers.

    • Example: Fetching data for a mobile app via an API.

  4. FTP (File Transfer Protocol):

    • For transferring files between a client and a server.

  5. SMTP and IMAP/POP3:

    • Used for email communication.


Communication Techniques:

  1. Request-Response (Synchronous):

    • The client sends a request and waits for the server's response.

    • Example: Loading a web page.

  2. Polling (Repeated Requests):

    • The client periodically sends requests to check for updates.

    • Example: Checking for new emails.

  3. Server-Sent Events (SSE):

    • The server pushes updates to the client.

    • Example: Live news feeds.

  4. WebSockets (Full-Duplex Communication):

    • Persistent connection where both client and server can send messages anytime.

    • Example: Real-time multiplayer games.

  5. Asynchronous Requests (AJAX):

    • The client sends a request without reloading the entire page, often using JavaScript.

    • Example: Infinite scrolling on a web page.


    We will use REST API calls for our application.


 

E) APIs


An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate with each other. APIs enable developers to access specific functionality or data of another application, service, or platform without exposing the underlying codebase.


Common Uses of APIs:

  1. Web APIs: Allow communication between client applications (e.g., mobile apps, browsers) and servers.

    • Example: Fetching weather data from a weather API.

  2. Third-Party APIs: Access functionality of external platforms.

    • Example: Integrating Google Maps or payment gateways like Stripe.

  3. Microservices Communication: Enable different services in a microservices architecture to communicate.

  4. Data Sharing: Allow applications to share data between systems.


APIs can be written using various approaches, each suited to specific needs. RESTful APIs (Representational State Transfer), the most common approach, use HTTP methods (GET, POST, PUT, DELETE) for communication, exchanging data in formats like JSON or XML. They follow principles like statelessness, where each request is independent, and resource-based URLs (e.g., /users for user data). REST APIs are easy to implement and compatible with browsers but lack robust support for real-time communication.



 

F) Basic Front End and backend Code project with docker compose


  • Project Structure-

project/

├── backend/

│ ├── app.py

│ ├── Dockerfile

├── frontend/

│ ├── index.html

│ ├── Dockerfile

├── docker-compose.yml




app.py ( backend pythoncode with fastapi)

The line app = FastAPI() is creating an instance of the FastAPI class, which is the main application object for your FastAPI web application. This instance (app) will serve as the central point for defining your application's routes, middleware, and other configurations.


The line @app.post("/process/") is a decorator in FastAPI that defines a route for handling HTTP POST requests to the /process/ endpoint. It specifies that this route will respond to POST requests, typically used for sending data to the server, such as form submissions or file uploads. The string "/process/" defines the URL path for the route, and when a client sends a POST request to this path, the associated function( process_message) is executed. This function processes the request data, performs any required operations (like saving to a database), and returns a response to the client.


For get request if we have sth like @app.get("/status_update"),@app.get() decorator is used to take get request at "/status_update" end point of fastapi server. ( The endpoint of a FastAPI backend server is the combination of the base URL where the server is running and the specific route defined in your FastAPI application. ) Then associated function with decorator will be executed.


Dockerfile ( Backend)



dockerfile

Lets understand the docker file commands first-


docker file commands

This Dockerfile sets up a lightweight Python 3.10-based environment for running a FastAPI application. It defines the working directory (/app), copies the FastAPI code (app.py) into it, installs the necessary dependencies (fastapi and uvicorn), exposes port 8000 for the backend, and runs the application using Uvicorn on all available network interfaces.


index.html ( Frontend)


HTML only front end

This HTML file creates a simple web page that allows users to send a message to a FastAPI backend service using a form. Let's focus on 1 line; <form action="http://backend:8000/process/" method="post">

This line defines an HTML form that sends data to the FastAPI backend using an HTTP POST request. Here's what it does:

  1. <form> Tag:Creates a form element that allows users to input data and submit it to a server.

  2. action="http://backend:8000/process/":Specifies the URL where the form's data will be sent when submitted. In this case, it sends the data to the FastAPI backend at http://backend:8000/process/.

  3. method="post":Indicates that the form data will be sent using the HTTP POST method, which is commonly used for sending data securely or when making changes on the server.

This line is essential for connecting the frontend (HTML) with the backend service and facilitating data exchange between them.


Dockerfile ( Front End)



Dockerfile: Frontend

Nginx starts as the web server inside the container.

It serves the index.html file from its default directory (/usr/share/nginx/html/).

The EXPOSE 80 line in the Dockerfile indicates that the container listens on port 80 for HTTP requests.


docker-compose.yml



Docker Compose- managing multiple containers

if there are multiple containers from same or different docker, we have to build them separately, name container separately, run them separately, mention port , context ( location of docker) and many other things related to build and run has to managed individually. To handle this we can take docker compose that will start all the containers through single command.


docker compose keys for yaml file

now it should be very clear that there are 2 services ( container) , context defines location of docker file that has to be build and port mapping container to system . Some are global keys like version, services while other are service specific like build, port etc.


now we need to build and start containers-

docker-compose up --build


  • docker-compose: This is the Docker Compose command-line tool that allows you to manage multi-container Docker applications. It reads the configuration from the docker-compose.yml file to handle container orchestration.

  • up: This subcommand is used to create and start the containers as defined in the docker-compose.yml file. It will create and start all the services (containers) that are defined in the file.

  • --build: This flag instructs Docker Compose to rebuild the images before starting the containers. It ensures that the latest version of the image is used, even if an image already exists. This is useful when there are changes to the Dockerfile or dependencies, and you want to apply those changes before running the containers.





3 views0 comments

Recent Posts

See All

Comments


bottom of page