BEST PRACTICES FOR CREATING A CONCURRENT API IN GOLANG

*Best Practices for Creating a Concurrent API in Golang
Project Overview
*

In this project, we will build a concurrent bulk SMS application for a telecom company called NAYY TELCO.

The main goal of this project is to understand how Golang handles concurrency using workers, jobs, and channels, and how this approach helps in sending bulk SMS messages fast and reliably.

Project Objectives

  1. Send bulk SMS messages to multiple customers.
  2. Use worker pools to process messages concurrently.
  3. Understand how Golang conceptualizes:
    o Jobs
    o Workers
    o Channels

  4. Build a clean API that can communicate with a React frontend.
    Technology Stack

Frontend

• React.js
• Tailwind CSS
• Axios
• react-router-dom

Backend

• Golang
• net/http (manual HTTP server)
• http.ServeMux (router)
• CORS middleware
• Goroutines, Channels, and WaitGroups

Frontend Overview
The frontend is built using React.js and provides a simple user interface for sending bulk SMS messages.
The form contains four input fields:
• Sender Name – The name of the sender (e.g., NAYY TELCO)
• Recipient Name – The name of the customer
• Recipient Number – The customer’s phone number
• Message – The SMS content to be sent

import { useState } from "react";
import axios from "axios";

export default function BulkSms() {
  const [from, setFrom] = useState("");
  const [messages, setMessages] = useState([
    { name: "", to: "", message: "" }
  ]);
  const [loading, setLoading] = useState(false);

  const handleChange = (index, field, value) => {
    const updated = [...messages];
    updated[index][field] = value;
    setMessages(updated);
  };

  const addRow = () => {
    setMessages([...messages, { name: "", to: "", message: "" }]);
  };

  const removeRow = (index) => {
    setMessages(messages.filter((_, i) => i !== index));
  };

  const sendMessages = async () => {
    setLoading(true);
    try {
      await axios.post("http://localhost:8080/api/sms/send", {
        messages: messages.map(m => ({
          ...m,
          from
        }))
      });
      alert("SMS sent successfully 🎉");
    //   setMessages([{ name: "", to: "", message: "" }]);
    } catch (err) {
      alert("Failed to send SMS");
    } finally {
      setLoading(false);
    }
  };

  return (
    

📩 Bulk SMS Sender

{/* Sender */}
setFrom(e.target.value)} placeholder="e.g. NAYY Telco" className="w-full border rounded-lg px-4 py-2 focus:ring focus:ring-blue-200" />
{/* Messages */}
{messages.map((msg, index) => (
handleChange(index, "name", e.target.value) } className="border rounded-lg px-3 py-2" /> handleChange(index, "to", e.target.value) } className="border rounded-lg px-3 py-2" />

Previous Post

Day 31: Configuring a Private RDS Instance for Application Development

Next Post

Monetzly: Boost Developer Revenue with AI Conversation Ads

Related Posts