Your Client's App Is Dying Quietly - And It's The API Nobody Built
Every quarter hundreds of businesses fall into this trap. They need a data integration between their e-commerce site and inventory software. Something gets added to their backlog, someone in IT writes a script using a CSV export / import system. It works for 6 months and then the product catalogue increases. The export now takes 4 hours instead of 10 minutes and one evening the import fails silently. The next morning the website is selling 34 items that are out of stock. 3 customers place an order, pay, and receive an apology email. One customer shares their experience on LinkedIn and the operations manager is asked in a meeting:
"don't just talk to each other."
There really isn't an answer. It's because there was never an API built. No one was hired to build an API because IT looked like a 2 day script.
That's where the freelancer comes in. Whilst the shiny parts of API development (integrating with Stripe, sending notifications with Twilio, building bots with Slack) are well understood, the boring bits are where the real value is. It's not commoditised, IT's not well understood and therefore IT can be charged accordingly.
This guide will help you build a business around this. We'll cover how to define your role, avoid scope nightmares with discovery, design principles to make the API maintainable, security considerations that your client won't know to ask about, deployment practices to separate yourself from script writers and finally pricing models.
Why API Work Costs More Than Regular Development
There is a structural issue in the freelance market meaning API work should be priced differently. Most development work is priced based on the availability of developers. API work is priced based on the risk.
APIs sit between systems. If they fail IT causes issues elsewhere. If your front end breaks IT can be embarrassing. If your API breaks IT will cause an outage, data loss or security issue. These issues will have a cost to the client that can be quantified by their finance team. You're not selling code, you're selling peace of mind.
There are very few developers who can do this. There are plenty that can write endpoints, but very few who can design a resource model that can scale with new features for 3 years, decide on an authentication method that will pass a security review, design meaningful error responses that can be debugged by the partners engineering team and document everything so that a developer joining the client can use IT without having to ask anyone.
API work is inherently retainer friendly. Whilst a web page is a finite project, an API will have different versions, deprecations, new consumers, new integrations, and IT needs to be kept secure. If you're hired to build an API you're a prime candidate to offer a retainer.
Role
As mentioned in the original article, you are a polymath.
You're defining the purpose of the API. Often clients come to you with a very vague brief. "we need an API so our mobile app can talk to our backend". It's up to you to define what this API will be. Who will consume IT? Will IT be an internal app, a partner or a public developer API? Each one will change how you design IT substantially. If IT's a public API you'll need to consider versioning, rate limiting and developer documentation. If IT's an internal API IT can be simpler but still needs to fit the security model of the organisation.
You're designing the data model. The most common reason an API becomes a nightmare to maintain is due to the resource model not being fit for purpose. If the client has a join table called customer_orders in their database, you should almost never expose this as an endpoint. Instead you should design IT so the consumer can get /customers/{ID}/orders. This is where the real value comes in.
You're deciding on the security model. Clients won't tell you what the authentication requirements are unless you ask. They won't think about what happens if a token is leaked, should a partner integration have access to all records or just their own. If you design an auth model that doesn't pass a security review you've given them a liability.
You're translating. You're able to explain why you've designed IT a certain way to a non-technical person approving the budget. If you can explain why you've designed IT a certain way (e.g. "this means your system will continue to function whilst your partners system fails") you're showing real value.
Discovery
The "doom questions" from the original article are a great starting point. However, to ensure you make a profit from the project, here is a full breakdown.
What happens if the API doesn't exist? This helps you understand what the real problem is. Are they looking to build a quick tool for internal use or a production system? This will massively affect how you approach the project.
Who consumes the API and what do they control? If IT's an internal mobile application you know who will be consuming IT. If IT's a partner integration you know another companies engineering team will be writing against your interface. This means you need to take their constraints into account. If IT's a public API you don't know who will be consuming IT and IT will add to your support burden.
Walk me through a users journey. What data needs to be passed at each stage? This will almost naturally give you your resource model and will highlight any edge cases.
How many requests do you expect to receive per day? How long should the response take? 100 requests vs 100,000 requests will have a completely different architecture. Often the client won't know this which is useful information. You'll need to design with scaling in mind.
How will you know if the API was successful in 6 months? This will be your acceptance criteria. This should be included in your written scope document.
At the end of discovery you'll have a spec document signed off by you and the client. This will include details of the resources, consumers, authentication model, error handling, performance and what done looks like. This protects you from the "I thought IT would also do X" conversations that can lose you otherwise profitable projects.
Design Principles
Most projects will use REST, and the 4 principles mentioned in the original article are correct. Resources should be nouns, HTTP verbs should be used appropriately, stateless and structured responses with meaningful status codes.
However, there are some design considerations to think about for year 2.
Consistent naming. Pick either snake_case or camelCase and stick with IT. If your API returns customer_id in one endpoint and customerId in another your consumer will raise a bug.
Consistent pagination. Any list endpoints that could return more than 50 results should have a pagination strategy. Make sure IT's consistent across all of them. Cursor based pagination scales much better than offset based.
Meaningful errors. As mentioned in the original article don't return a generic 500. Instead return a structured response with a code (machine readable), message (human readable) and most importantly a request ID. This is the most useful thing you can give for debugging.
Idempotent writes. If the client makes a POST request and loses connection before receiving a response they will attempt to resend the request. Without an idempotency key this will result in a duplicate record. An idempotency key is a unique identifier provided by the client. The server stores this with the request so if IT detects IT's an attempted resend IT will return the original result. This is standard practice for any payment/order handling API. It's often overlooked.
Versioning. Adding /v1/ to your endpoints is free and ensures that if you ever need to make a breaking change, none of your existing consumers will break. If you deliver an API without versioning you've created a future nightmare.
Developer Experience
As mentioned in the original article this is your secret weapon.
Interactive documentation. Using OpenAPI specs you can generate documentation using Swagger. This allows the developer to make requests in the browser. An API with great interactive documentation will be adopted quicker and will reduce your support burden.
Quickstart. Can they make a 3 line request that authenticates, makes a request and prints the response? If they can't (wrong base URL or missing step in the auth flow) they will instantly lose trust in you.
Webhooks. Most modern integrations will require the client to be notified when things change. A well designed API will contain webhook events with retries, signatures and a guaranteed delivery.
Sandbox. A test environment with seeded data is worth more than any documentation page. It allows the consumer to play around without affecting production.
Security
This is where you'll either gain trust or create a liability. Clients won't be able to judge how good your work is.
Authentication. Use OAuth 2.0 for 3rd party / public APIs, API Keys for internal services. Never use a custom authentication method. If you do you'll be mentioned in an incident report.
Authorisation. This is where you define what they can see. The most common vulnerability on an API is broken object level authorisation. This means that an authenticated user can request another users record by changing the identifier in the URL. All endpoints that accept an object ID should verify the authenticated user has permission to view that specific object.
HTTPS. Always use HTTPS. Minimum TLS 1.2. HSTS headers.
Validation. Never trust any input from the client. Always validate types, lengths, formats and ranges on the server. If you rely on client side validation you've created an injection vulnerability.
Rate limiting. Limit requests per user and per endpoint. Give clear 429 responses and retry after headers. Rate limiting isn't just to stop abuse, IT's to ensure the service is resilient. If one bad consumer is making too many requests IT can impact everyone.
Deployment
As mentioned in the original article, everything should be replicatable.
Containerisation. Using a Docker image will mean your API behaves the same on the developers machine, staging and production. This removes an entire category of issues. The image should be built using your pipeline.
Infrastructure as Code. Using Terraform (or similar) you're defining your infrastructure (database, API Gateway, Networking, IAM Roles) using version controlled files. This means the client team can see exactly what has been built and can make changes after the engagement.
Automated CI/CD. On merge to a specific branch the tests will run and deployment will happen. Your pipeline will run your unit tests, integration tests and security scan. If any of these fail the deployment will be blocked. This guarantees quality from you and means a small team can deploy with confidence.
Pricing
If you have a clearly defined scope you should price this as a fixed fee project. Price based on the scope and the value. If you're replacing a $10,000 per month SaaS subscription IT's worth much more than the hours you'll spend building IT. Don't price IT based on the hours.
If you're providing advice, troubleshooting or the scope truly can't be defined you should price IT hourly. This is the worst value capture and should be used sparingly.
This is where you'll make your business sustainable. APIs need maintaining, upgrading versions, onboarding new consumers, patching security and monitoring performance. Offering a retainer of $2000-$8000 per month will mean you have a defined support scope and you've turned a project into a relationship.
Always price based on the risk you're removing. The client could have an API that relies on nightly CSV exports. This isn't priced based on the hours you'll spend, IT's priced based on what happens when they send the wrong items in the morning.
Getting Started
To get started you should decide what type of API problems you want to specialise in. Do you want to focus on internal integrations, partner APIs, public developer APIs or a particular vertical (fintech / logistics). You should also have 2-3 examples in your portfolio.
A public API you've built as a personal project, properly documented, with a working quickstart and interactive documentation will look much better than a list of technologies. It shows that you can do what the client is paying you for. Take a vague requirement and turn IT into a reliable, documented and secure interface that other systems can rely on.
This is your product. The code is just the mechanism. The trust is the business.
Comments
Post a Comment