Editorial read

Blog

/

From the Chaos of 27 RGs to th...

Tech

From the chaos of 27 RGs to the Single Primary Key: How the CIN Fixed Brazil's Highest Technical Debit

Áquila Ramos

Áquila Ramos

CEO na TechIssues

September 29, 2026

From the Chaos of 27 RGs to the Single Primary Key: How CIN Fixed the Greatest Technical Debt in Brazil

Technology usually evolves silently behind the back of government, but there are structural changes that completely redefine the way a country works. One of them is the transition from the old RG to the National Identity Card (CIN) It is not just a plastic paper exchange, an aesthetic whim or any form of politics; it is the resolution of one of the biggest architectural failures in the country's history.

Part 1: The Great Mask Dance

Imagine you decide to go to a huge network of academies that has 27 units, one in each state of Brazil. You arrive in the São Paulo unit, you register and they give you a wallet with 123.

A few months later, you travel to Rio de Janeiro and decide to train in the unit there. Instead of their system simply reading their São Paulo wallet, the support agent says: "Here we have another system. Let's make a new postcard for you."And they give you a new number: 456. If you travel the country and go through all states, you will end the year with 27 different postcardsWith 27 different numbers, and none of them talk to each other.

For the network of academies, you are not a single person who uses all 27 academies, because their database, you seem to be 27 different customers, because there are 27 different wallets.

This is exactly what happened with the General Registry (RG) in Brazil. As the issue of the RG was always the responsibility of the Public Security Secretariats of each state, Brazil operated in a true "key chaos". João da Silva could take out an RG in São Paulo, another in Minas Gerais and another in the Holy Spirit. He remains the same John, but for the state ecosystem, he had multiple valid identities.

A CNI It's enough to light the light of this mask dance. It tears the 27 state posters and from now on there is only one identity in the entire country. And the universal "sign" to find you in any government system becomes your CPF.

Part 2: The Cost of Technical Debt > Retrieval math and impact on systems

If we look at the previous model from the perspective of software engineering and database modelling, Brazil accumulated a multi-billion dollar technical debit. We will translate the old model of RGs into numbers, matrices and processing complexity to understand the size of the damage.

1. Mathematics of the Amostral Space and Fraud

Brazil has an estimated population of approximately 212 million inhabitants. In the ideal model (one document per person), we should manage exactly 212 million identity records.

However, as each citizen could have an RG per state:

Maximum Theoretical Atmospheric Space = 212,000 x 27 = 5.724,000,000 records

More than 5.7 billion possible combinations of identity documents for a population of just over 200 million. This gigantic gap created a perfect attack vector for tax fraud, staloniato and undue social benefits, costing billions of reals annually to public safes in audits and investigations.

2. The Hell of "De-Para" Sheets (Spare Matrixes)

When a federal system (such as Dataprev, SUS or Federal Revenue) needed to cross data received from different states to consolidate a citizen's record, data engineers were forced to deal with Sparrow Matrixes and bizarre relational mapping tables.

To unify the registry, the table of a benefit system needed to have a structure similar to this one:

The computational problem here is double:

  1. Storage and indexing waste: Maintain 27 indexable index columns to cover all state possibilities degrades the perfoamance of the queries.

  2. High latency queries: To check whether a citizen already existed in the system using only RG, the query needed to sweep multiple fields, or appeal for unexact text searches, since each state adopted a pattern of formatting different digits and letters for RG.

3. The Algorithm Complexity of Data Crossing (O) N² ))

Without a universal primary key, public bodies often needed to use algorithms to Fuzzy Matching (probabilistic combination of strings) to try to guess if two lines in different databases belong to the same physical person.

The system took the full name, mother's name and date of birth to calculate the Distance from Levenshtein (the number of modifications needed to transform one string into another).

  • In terms of computational complexity, comparing massive databases in a probabilistic way approaches a complexity of O(N2) in raw scenarios of unreplication, requiring massive clusters of servers rolling heavy processing routines (ETL) that lasted days.

4. Clean Architecture with CIN ($O(1) $)

With the implementation of the CIN and the adoption of the CPF as the unique and universal indexer, the government's data architecture is instantly cleaned up.

  • Contract Strict: The CPF follows a clear mathematical rule (two digits verifiers based on remaining division by 11). It is immutable and unique to the individual.

  • Complexity $O(1) $: Instead of scanning scattered tables or running probabilistic algorithms to check if the John of SP is the same John who operated in the SUS in Santa Catarina, the system does a direct search based on a single indexed primary key (B-Tree). The answer is immediate.

The CIN transforms public identification in Brazil into a standardized, safe and high performance API. The citizen gains in red tape on the portal Gov.br, and the state saves infrastructure, reduces engineering re-routing and closes doors to the invisible drain of identity fraud.

0 views

Published 22 days ago

← Back to the blog