Why APIs Exist : Introduction


You're sitting at home, opening Paytm to book a train ticket to Delhi. Within seconds, you see all available trains, select your berth, make payment, and done - ticket booked. But wait, aren't these IRCTC's trains? How did Paytm book them?
Or think about this - you can book the same Rajdhani Express ticket from IRCTC website, MakeMyTrip, Goibibo, Amazon, or even Google. How can so many different apps book the exact same seat?
The answer is APIs, and this is the story of how they revolutionized not just train booking, but the entire internet.
When IRCTC First Went Online
Let's go back to the early 2000s. IRCTC launched online ticket booking - a big deal at that time. No more standing in queues at 4 AM!
Their system was built like a typical sarkari office - everything in one building, all departments under one roof. The website, the booking system, and the database were all packed together like a joint family living in one house.
graph TD
A[IRCTC System - All in One]
A --> B[Website: What you see]
A --> C[Logic: Booking process]
A --> D[Database: All train info]
style A fill:#ffcc99
This worked fine initially. You opened IRCTC website, selected your train, and booked your ticket. Simple. But there were problems:
When tatkal booking opened at 10 AM, the entire system would crash
If they updated the website design, sometimes booking would stop working
One small bug could bring down everything
Only IRCTC could sell IRCTC tickets
It was like having only one ration shop for the entire city. It works, but imagine the queues!
The Problem: Everyone Wanted to Sell Train Tickets
By 2010, smartphones arrived. People were booking flights on MakeMyTrip, paying bills on Paytm. These companies came to IRCTC with a request: "We have lakhs of users. Let us also sell train tickets. It's good for everyone."
IRCTC faced a dilemma. How to let others sell tickets without giving them access to everything?
Option 1: Give Database Password? This would be like giving your house keys to all your neighbors. What if:
Someone accidentally deletes tomorrow's train schedule?
Someone sees all passenger's personal details?
Someone books 1000 tickets in one second and crashes the system?
Someone steals payment information?
Absolutely not. This was as dangerous as sharing your Aadhaar number on Facebook.
Option 2: Let Everyone Build Their Own System? Imagine if MakeMyTrip, Paytm, and Google each maintained their own list of trains and seats. Three systems trying to book berth number 45 in coach S7 at the same time. Who gets it? It's like three people trying to sit on the same seat in a bus - chaos!
The Brilliant Solution: APIs
Someone at IRCTC had an idea that changed everything. Instead of giving everyone access to their kitchen, why not create a window where people can place orders?
Think of your favorite restaurant. You don't walk into the kitchen and cook your food. You tell the waiter what you want, and they bring it to you. The kitchen remains private and secure.
This "waiter" is what techies call an API - Application Programming Interface. Don't let the name scare you. It's just a messenger that carries requests and brings back answers.
Here's what IRCTC did:
Separated their system into independent parts
Created an API - a controlled gateway
Gave approved companies permission to use this gateway
Set rules on what they can and cannot do
How It Actually Works
Let me show you what happens when you book a ticket on Paytm:
Step 1: You search for Mumbai to Delhi trains
Step 2: Paytm's app sends a request to IRCTC's API:
{
"from": "Mumbai",
"to": "Delhi",
"date": "26-12-2024",
"class": "SL"
}
Step 3: IRCTC's API checks the database and replies:
{
"trains": [
{
"name": "Punjab Mail",
"number": "12138",
"departure": "19:10",
"available_seats": 120,
"fare": 485
},
{
"name": "Mumbai Rajdhani",
"number": "12951",
"departure": "16:35",
"available_seats": 23,
"fare": 2850
}
]
}
Step 4: Paytm shows you this information beautifully with their design
Step 5: When you book, same process - Paytm tells API, API tells IRCTC, ticket gets booked
The beauty? Paytm never saw IRCTC's database. They just asked questions and got answers. Like ordering food through a window - you get your food, but you never enter the kitchen.
graph LR
User[You] --> Paytm[Paytm App]
Paytm --> API[IRCTC API]
API --> Backend[IRCTC System]
Backend --> Database[(Train Database)]
Database --> Backend
Backend --> API
API --> Paytm
Paytm --> User
style API fill:#90EE90
style Database fill:#FFB6C1
This Solved Many Problems
Remember when companies built different apps for everything? One team for website, another for Android app, another for iPhone app. It was like cooking the same dish in three different kitchens - waste of resources.
APIs changed this. Now:
Build one backend system
Create one API
Everyone connects to the same API
Whether you're using IRCTC website on laptop, their app on phone, or booking through Google, everyone talks to the same API. Update train fare once, everyone sees the new price. Fix a bug once, it's fixed everywhere.
APIs Are Everywhere in Your Life
Every day, without knowing, you use dozens of APIs:
When you order food on Zomato:
Login with Google → Google API
See restaurant location → Maps API
Pay online → Payment gateway API
Track delivery boy → Maps API again
Get SMS updates → SMS API
When you book an Uber:
See available cabs → Uber's API
See route → Google Maps API
Pay → Paytm/Payment API
Share trip with family → WhatsApp API
When you check weather on your phone:
- Your weather app → Weather department's API
It's like how every shop in your area accepts UPI payments. The shop doesn't build their own payment system. They use Paytm, PhonePe, or Google Pay's API. One system, many users.
The Bigger Picture: OpenAI and ChatGPT
You've probably heard about ChatGPT. OpenAI spent crores developing this AI. But you can use it in hundreds of different apps. How?
Through APIs.
OpenAI has one super-intelligent AI system. When any app wants to use AI:
App sends your question to OpenAI's API
API asks the AI brain
API sends back the answer
App shows you the result
It's like having one expert doctor in the city, and everyone consults through phone calls. The doctor is one, but patients are thousands. This is why suddenly every app has AI features - they're all using the same few AI APIs.
What If APIs Didn't Exist?
Imagine a world without APIs:
You'd need 50 different apps for 50 different banks
No UPI - every shop would need their own payment system
No Google Maps in Uber - they'd build their own maps
No "Login with Google" - remember passwords for 500 websites
IRCTC would be the only place to book train tickets
No food delivery apps - each restaurant would need their own app
It would be like going back to when every shop only accepted cash from their own printed coupons. Technically possible, but what a nightmare!
The Security Aspect
"But isn't this dangerous? What if someone misuses the API?"
Good question. APIs are built with security in mind:
Authentication: Every company gets a unique "key" - like a visitor ID card in an office
Permissions: Paytm can book tickets but can't change train schedules
Rate Limits: Can't book 10,000 tickets per second
Monitoring: Every request is logged and watched
Revocation: Misuse the API? Access blocked immediately
It's safer than giving database access, like how UPI is safer than giving someone your debit card.
Why This Matters for India
APIs have been revolutionary for Digital India:
Aadhaar API: Instant identity verification anywhere
UPI APIs: Any app can add payment features
DigiLocker API: Access documents from any government website
GST APIs: Automatic tax filing for businesses
CoWIN API: Multiple apps could show vaccine slots
Small startups can now compete with big companies. You don't need Flipkart's budget to accept online payments. Just integrate a payment API. You don't need Google's technology to show maps. Just use their API.
A college student can build an app that books trains, accepts payments, sends SMS, and shows maps - all using APIs. Without writing any of that complex code themselves.
The Simple Truth
APIs are just a safe way for different software to talk to each other. Like how you can transfer money to anyone using UPI without knowing their bank details, APIs let apps work together without sharing sensitive information.
They're the reason your phone can do so much without having 1000 different apps. They're why a small startup can offer the same features as big companies. They're why the internet works as smoothly as it does.
Next time you:
Book a train from any app
Pay using UPI anywhere
Login with Google
Track your delivery
Check live train status
Remember, it's APIs making it all possible. They're the invisible bridges connecting our digital world.
The internet without APIs would be like India without tea stalls ☕️ - technically possible, but not the world we'd want to live in.
Note: This article is for educational purposes only. All company names, services, and examples mentioned (IRCTC, Paytm, MakeMyTrip, Google, Zomato, Uber, OpenAI, etc.) are used solely for illustration and understanding. The actual implementation details may vary. The scenarios presented are simplified for clarity and may not reflect the exact technical processes these companies use.
Feedback Welcome: Found this helpful? Have suggestions to make it better? Feel free to share your thoughts. Understanding technology should be simple and accessible to everyone.
Share this with someone who always wondered how the same train ticket can be booked from different apps!
Thank you.
Subscribe to my newsletter
Read articles from VinayC directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
