Fundai

One company, four spellings: when identical text isn't identical

One stock symbol reached Fundai in four invisible spellings, so exact matching hid companies. The rules and the one normalization function that fixed it.

By 4 min read

In short

Text that looks identical can differ underneath: zero-width characters, ordinary spaces, Arabic look-alike letters and other numeral sets. Fundai now sends every symbol through one function that builds a matching key and maps it back to the single spelling the database stores. It forgives what people and sources type, stores one spelling, and never guesses: an unknown symbol is left as it is and an ambiguous one is logged for a person.

Type "Cafe" into a search box and miss everything filed under "Café", and you've met this problem. In a product I co-founded in 2023, it was quietly hiding companies from investors, and it was invisible to the eye.

Fundai is a stock-research platform for the Tehran Stock Exchange. Investors use it to look a company up and read its financial reports, prices and fund data in one place, in Persian or English. Behind that, Fundai pulls data from several public sources, and each one refers to a company by its short trading symbol, the way "AAPL" stands for Apple.

What investors ran into

Fundai has one search box. An investor types a company's symbol the way their keyboard writes it, or the way another website writes it, and expects the company to appear. If it doesn't, the natural conclusion is that we don't cover it, and very few people try typing it a second way.

A quieter version of the same problem sat behind the scenes. A company's page is only as complete as the reports we import for it, and an import that silently skips a company leaves a gap nobody reports, because nobody knows a report should be there.

What I found

I followed one company's reports from the sources into our database and compared how each source wrote its symbol, "fan-afzar". On screen, every version looked the same. Underneath, they weren't:

  • the official filings site joined the two halves with an invisible zero-width character;
  • another page used an ordinary space;
  • the exchange's data feed used Arabic forms of two letters that look identical to the Persian ones;
  • some feeds added a trailing space, or wrote digits in a different numeral set.

Our import code looked each company up by an exact match on whatever the source sent. So when a source used a different invisible character, the lookup found nothing, and the report was dropped without an error. The search box had the same weakness: typing the symbol with a space didn't find the stored version.

Four spellings of one symbol from three sources, folded into one matching key and mapped back to the spelling we store.

Deciding how it should behave

Before writing any code, I settled what the product should promise, because "make matching looser" can do real harm in a product people make money decisions with.

Be forgiving where people type, and strict where we store. Any spelling an investor or a data source sends should find the company, but the database keeps exactly one spelling, so a company never splits into two pages with half the history each.

Let people search by what they know. The same box now finds a company by its symbol in any spelling, by its Persian name or by its English name, because someone who knows the company but not its symbol was getting nothing back.

Never guess. If the data itself is ambiguous, or a source sends a symbol we don't recognise, the system doesn't pick the closest match. Showing an investor one company's reports under another company's name is far worse than showing nothing, so an unknown symbol is left as it is, and an ambiguous one is logged for a person to fix.

How it works

With the rules settled, the engineering was deliberately small. Every symbol that enters the system, from a data import, an admin form, a scheduled job or the search box, goes through one function first.

That function turns the symbol into a matching key: it removes every invisible character and space, converts the Arabic look-alike letters to their Persian forms, and turns every numeral set into plain digits. All four spellings collapse into the same key. The key is then mapped back to the one spelling our database stores, using a lookup table built from every symbol we hold, a little over a thousand of them.

key = normalize_symbol(source_value)   # strip invisibles, unify letters
symbol = symbol_map().get(key)         # the one spelling we store
if symbol is None:
    return source_value.strip()        # unknown: keep it, never guess

The lookup table is cached so an import of thousands of reports stays fast, and it refreshes whenever a company is added or edited. One detail mattered there: a refresh that was already running could finish just after a new company was saved and put the old table back for up to an hour. Each refresh is now stamped with a version number that every save moves forward, so a late refresh can't overwrite a newer one. If the cache is unavailable, the table is built straight from the database: slower, but never broken.

How I made sure it holds

Automated tests check each spelling finding the stored company, an unknown symbol being left alone, the search box finding a company across invisible differences, a newly added company being found immediately, and ambiguous data never being guessed at. The refresh race has its own test, which fails on the version without the version number.

What any product can take from this

Most products take names from people or other systems: customer names, cities, product codes, company identifiers. The same lessons apply well beyond Persian:

  • Decide the promise first: where the product forgives differences, where it stays strict, and what the user sees when nothing matches.
  • When people make decisions on your data, an honest "not found" beats a confident wrong answer.
  • Clean up text once, at the point it enters the system, in one function everything uses, rather than in every feature separately.
  • Watch for invisible differences: "São Paulo" and "Sao Paulo", a curly apostrophe in "O’Brien", a non-breaking space copied from a web page.

Have you been caught out by two pieces of text that looked identical but weren't? I'd like to hear where it showed up.

Further reading

  • Unicode
  • Text normalization
  • Search
  • Data import
  • Persian

More writing