Java and Spring Boot
I Got to the Fish Market Too Late. So I Built a Backend.
How a Sunday morning in Kandy turned into FreshLink — and everything Java taught me along the way
By Sudeshkar12 min read
Every Saturday or Sunday morning, my dad and I go to the UDF fish market in Kandy.
If you know Kandy, you know UDF. It is not a fish market — for most people around here, it is the fish market. There is no real alternative. That is just how it is.
We always go early. Not because we are disciplined people, but because everyone knows what happens if you do not. The good fish goes. Fast.
One Sunday we got late.
I remember standing there looking at the trays and just… nothing. Nothing worth buying. What was left was the fish nobody else wanted, sitting a little too long, a little too dull. We went home more or less empty-handed.
And on the drive back, something clicked in a way I could not shake off.
There is clearly demand here. Kandy is not a small town. There are homes, hotels, cafés, restaurants — all of them needing fish, every single day. And the entire thing runs through essentially one place. Yes, you can buy fish at Keells or Food City. But if you have ever bought fish from a supermarket freezer and compared it to something landed that morning, you know it is not the same conversation.
So the demand exists. The demand is obvious.
The question that stuck in my head for weeks after was: where is the supply, then?
The phone call from Jaffna
I already knew the answer. I just had not connected it yet.
A while back, a relative uncle of ours in Jaffna called my cousin asking for help. This uncle is not a small operator — his family runs six or seven boats. They employ people. They go out, they catch fish in real volume, and they need to sell it.
And they have a problem that has nothing to do with fish.
They don’t speak Sinhala.
Think about what that actually means in practice. You have a genuine business, real supply, real quality — and you cannot negotiate. You cannot call a hotel in Kandy and pitch. You cannot build a relationship with a café owner who does not share your language.
So what do they do? They do the only thing that works. They catch in bulk, drive all the way down to the Dambulla market, and sell the whole lot at whatever price is being asked that day. A ton of fish. Sometimes more. Whatever species the season is giving them.
They take the price. They do not set it.
And then that fish gets bought, resold, moved again, marked up at every step — and eventually some of it reaches Kandy, a day or two older than it needed to be.
The moment it actually became an idea
Sitting with those two things side by side is what did it:
JAFFNA KANDY
┌────────────────┐ ┌──────────────────┐
│ 6-7 boats │ │ Cafes, hotels, │
│ Tons of fish │ │ restaurants, │
│ Every week │ │ households │
└───────┬────────┘ └────────┬─────────┘
│ │
HAS SUPPLY HAS DEMAND
No buyers One supplier
No language No alternative
│ │
▼ ▼
┌────────────────┐ ???????????????? ┌──────────────────┐
│ Dump it whole │ <-- nothing here --> │ Take what is │
│ at Dambulla │ │ left │
│ at their price │ │ │
└────────────────┘ └──────────────────┘There is no connection between these two. None.
And my uncle is not special. There must be dozens of families like his along the coast — Negombo, Trincomalee, Chilaw, Kalpitiya — sitting on serious supply with no direct line to the people who actually want it. Meanwhile every café owner in Kandy is showing up at 5am hoping for the best.
Both sides lose. The supplier loses margin. The buyer loses freshness. The only winners are the layers in between.
So the idea was almost embarrassingly simple:
What if a supplier could just… reach the cafés directly?
Not another marketplace app. Not a delivery startup. Just a proper, structured connection between people who have fish and people who need fish, with a record of what was ordered and who is accountable for it.
I called it FreshLink.
Meanwhile, I was learning Java like a maniac
Here is the part that made the timing work.
Around all of this, I was deep into learning Java. Not from a paid bootcamp — from free resources, mostly YouTube. Telusko was the big one for me. If you have learned Java in the last few years you probably know exactly the videos I mean. That channel took me from “what is a class” to actually understanding what Spring Boot is doing under the hood.
And there is a specific stage in learning backend development where you have absorbed a lot of concepts but built nothing real. You know what @Service does. You know what dependency injection means. You have written maybe four CRUD tutorials.
And then you sit there thinking: okay, but what do I actually build?
I had just been handed the answer at a fish market.
That is honestly the best part of this whole thing. I did not go looking for a project idea. The idea found me because I was paying attention to something that annoyed me in real life.
What FreshLink actually is
The core insight is that this market has two completely different buying behaviours, and a system that only handles one of them is useless.
The spot market. A café needs fish today. A supplier has fish today. Browse, order, done. This is the obvious one.
Forward demand. This is the one that actually solves my uncle’s problem. A café says “I need 40kg of tuna on Thursday.” A supplier records what they landed this morning. The system matches them — automatically, ranked by how fresh the catch is and how reliable the supplier has been.
That second flow is the whole reason the project exists. It is the difference between a shop and a supply chain.
SPOT MARKET DEMAND MATCHING
─────────── ───────────────
Supplier lists fish Supplier records today's catch
│ │
▼ ▼
Café browses market Café posts demand for Thursday
│ │
▼ ▼
Café places order ────► Matching engine pairs them
│ │
▼ ▼
Supplier accepts Supplier accepts the match
│ │
▼ ▼
Delivery ──► Complete ──► Rating Becomes a real order ───┘Building it: the architecture
I went with a fairly classic layered Spring Boot structure. Nothing exotic. When you are learning, boring and correct beats clever and fragile.
Controller ──► Service (interface) ──► ServiceImpl ──► Repository ──► PostgreSQL
│ │
▼ ▼
DTO ◄────────── Mapper ◄────────── EntityOne rule I committed to early and never broke: entities never cross the controller boundary. Everything going in or out is a DTO, mapped by hand.
This felt like extra work at first. It is not. The moment you have bidirectional JPA relationships and you try to serialise an entity straight to JSON, you get infinite recursion and a very confusing afternoon. Ask me how I know.
The domain model ended up looking like this:
┌──────────────┐
│ user_table │ JOINED inheritance
└──────┬───────┘
┌────────────┼────────────┐
┌─────▼────┐ ┌────▼───┐ ┌─────▼──────┐
│ admin │ │ cafe │ │ supplier │
└──────────┘ └───┬────┘ └─────┬──────┘
│ │
┌───────────┤ ├──────────────┐
│ │ │ │
┌───────▼──────┐ ┌──▼─────┐ ┌────▼────┐ ┌──────▼───────┐
│demand_request│ │ orders │ │ fish │ │ daily_supply │
└───────┬──────┘ └──┬──┬──┘ └────┬────┘ └──────┬───────┘
│ │ │ │ │
│ ┌────▼┐ │ ┌──────▼───────────┐ │
│ │items│ │ │fish_price_history│ │
│ └─────┘ │ └──────────────────┘ │
│ │ │
│ ┌─────▼────┐ │
│ │ delivery │──► delivery_route │
│ └──────────┘ │
│ │
└──────────► supply_match ◄──────────────┘Three roles — SUPPLIER, CAFE, ADMIN — using JOINED inheritance so every account shares one identity table but keeps its own type-specific columns.
How I built it, step by step
I did not build all of this at once. It grew in layers, and honestly the order mattered a lot:
1. AUTH & ROLES JWT, refresh tokens, three roles
│ "can the right people get in"
▼
2. THE SPOT MARKET Listings, orders, accept/reject/deliver
│ "can a café buy fish"
▼
3. DEMAND MATCHING Daily supply, demand requests, the engine
│ "can supply find demand automatically"
▼
4. TRUST Ratings, soft deletes, ownership checks
│ "can both sides rely on it"
▼
5. OPERATIONS Migrations, Docker, CI, health probes
│ "can this actually be deployed"
▼
6. INSIGHT Price history, market analytics, routes
"does it make anyone smarter"Every one of those layers taught me something the previous one could not have.
The matching engine (the fun part)
This is the piece I am most proud of, and the piece that broke in the most interesting ways.
When a café posts demand, the engine looks at every available catch of that fish type and allocates greedily — but the ranking is where the domain logic lives:
Rank available supply by:
1. Freshness score ──► the freshest catch goes first
2. Supplier rating ──► then whoever has been most reliable
3. Catch time ──► then oldest-first, so nothing sits
Allocate until the demand is filled,
creating a PENDING match per source.Sounds simple. It was not.
Things that broke, and what they taught me
This is the section I actually want people to read, because tutorials never show you this part.
1. My matching engine was allocating the same demand over and over.
The scheduler re-runs matching every ten minutes for demand that is still unfilled. My first version re-allocated from scratch every single time. So a 30kg request picked up another 30kg match on every pass. Four passes later: 120kg allocated against a 30kg order, all of it fake.
Lesson: with anything scheduled and repeating, always ask “what happens the second time this runs?”
2. Then I fixed that and created a deadlock.
I made pending matches reserve supply so it could not be double-promised. Correct. Except MatchStatus.EXPIRED existed in my enum and nothing ever set it. So a match a supplier simply ignored locked that fish away forever. It could never be offered to anyone else.
I created that bug by fixing another one. That is a very normal thing that nobody warns you about.
3. Two accounts could touch each other’s data.
This one still makes me wince. I had role checks with @PreAuthorize — so only cafés could hit café endpoints. But inside, some methods took an ID from the URL and just... used it. Any café could cancel any other café's order.
The fix was to enforce ownership in the service layer, not the controller. And to return 404, not 403 — because a 403 confirms the record exists and lets someone enumerate IDs.
4. My money was wrong.
The admin dashboard summed every order item with no status filter. Cancelled and rejected orders were being reported as revenue. Meanwhile the supplier leaderboard did filter on completed — so the same dashboard contradicted itself.
5. Two numbers described the same fish.
Fish.availableKg (the market listing) and DailySupply.quantity (the catch record) tracked the same physical fish independently. Recording a catch touched one and not the other. The spot market and the matching engine could each believe they had stock the other had already sold.
Fixing this meant deciding, properly, which one is the source of truth. One ledger. The catch record credits it.
6. Two people ordering at once could oversell a supplier.
I had a @Version column on Fish for optimistic locking. I had never actually tested it under concurrency.
So I wrote a test that fires real simultaneous transactions from a latch. Then — and this is the part I would tell every beginner — I removed the @Version annotation and ran it again to make sure the test would actually catch the problem:
Without optimistic locking:
Two 60kg orders vs 100kg stock ──► BOTH succeeded (120kg sold from 100kg)
Three 8kg orders vs 10kg stock ──► ALL THREE succeeded
Eight 5kg orders ──► 8 succeeded, only 5kg reserved
(7 reservations vanished silently)That last line is the scary one. No error. No exception. The supplier’s books just quietly disagree with reality.
A concurrency test that has never been seen to fail proves nothing.
Lessons that were not about fish at all
Some things I only learned by getting them wrong:
mvn test does not run your integration tests. Surefire picks up *Test. *IT classes belong to Failsafe. Without it configured, my integration tests sat in the repo executing never, while the build cheerfully reported green.
Mocked repositories agree with whatever you expect. My market browse endpoint returned a 500 for every unfiltered request — LOWER() on a null parameter makes PostgreSQL infer bytea and fail. Not one unit test could have caught it. They all mock the repository. Some things need a real database.
@Transactional will roll back your deliberate actions too. I wrote refresh-token replay detection: if a spent token is presented, revoke every session for that account. It returned a perfect 401 — and revoked nothing, because the throw rolled back the delete that preceded it.
The API looked correct. It was completely broken. I only found it because I checked the database instead of trusting the status code.
Where it is now
99 tests 78 unit + 21 integration
7 migrations Flyway owns the schema; Hibernate only validates
54 endpoints documented in Swagger
CI every push: unit + integration + Docker build
against real PostgreSQL and RedisIt has JWT auth with rotating, hashed refresh tokens. Rate limiting on the endpoints that need it. Soft deletes that keep trade history intact. Delivery tracking with a driver and an ETA. Routes, so one van can carry six cafés. Price history, so a café can tell whether today’s offer is fair.
Is it running in production, serving real fish markets in Kandy? Not yet. I want to be honest about that.
But it is not a tutorial project either. It has migrations, health probes, a container build, and a test suite that has caught real bugs — including bugs I introduced while fixing other bugs.
What I would tell someone starting out
Build the thing that annoys you. I did not brainstorm this. I stood in a fish market at the wrong time of day and got irritated. That irritation carried me through months of debugging in a way “build a todo app” never would have.
Free resources are genuinely enough. Telusko took me from confused to dangerous. What free resources cannot give you is a real problem to point the knowledge at. You have to find that yourself.
Your first version will have bugs you cannot imagine yet. Not syntax errors. Logic that looks perfect and is quietly wrong. The only defence is testing the things you are sure about.
Write down what breaks. Every one of the bugs above is now a comment in my codebase explaining why the code is shaped the way it is. Future me is going to need that.
What is next
More analytics on the demand side, so a supplier can see what Kandy actually wants before they load the truck. Push notifications instead of just email. Route optimisation — ordering the stops, not only grouping them.
And at some point, the real test: showing it to an actual supplier and an actual café owner and finding out how much I got wrong.
Because right now this is a well-engineered answer to a problem I observed. It is not yet a well-engineered answer to a problem I have validated. That is a different thing, and I know the difference.
But it started with getting to the fish market too late on a Sunday morning.
Not a bad trade.
FreshLink is a Spring Boot 4 / Java 21 / PostgreSQL backend. If you are learning backend development and want to see what a mid-size real project actually looks like — including the mistakes — the code is on my GitHub. https://github.com/sudeshkar/FreshLink-Backend
If you are in the fish business in Sri Lanka and any of this sounds familiar, I would genuinely like to hear from you.