‘In theory, Gen AI could be useful. In practice, the likelihood of errors was enormous.’
Bet365 had a breakthrough by combining metadata tagging and GraphRAG to give gen AI the all-important context it needed.
Like painting the fabled Forth Bridge, code modernisation is a continuous process. Over time, as a platform expands and evolves, the complexity of the modernisation task increases. New features are added, old logic is reworked and legacy systems are patched to meet modern demands.
At a business like bet365, which deploys hundreds of changes a week, keeping pace requires a sustained effort in an environment of growing complexity.
With the emergence of LLMs and generative artificial intelligence (gen AI) we now have the potential to transform this arena by automating refactoring at scale, accelerating documentation and assisting with legacy system interpretation.
However, efforts to make this a reality have been hampered by one critical flaw: context. You can feed an LLM every line of code you’ve ever written, but without the business context, the AI lacks the ability to generate code that’s truly fit for purpose.
That is, until a recent breakthrough changed the game. By utilising a GraphRAG approach, bet365’s Platform Innovation team has unlocked a new standard in scalable, human-aligned code modernisation. Gen AI now has the potential to take on the heavy lifting, while expert engineers step into a new role.
Let’s break it down.
The code modernisation challenge
At bet365, modernising legacy code is a resource-intensive process that requires consistent effort from a team of dedicated experts. The interconnected nature of our systems means that every change has the potential to have a knock-on effect on other parts of the system. Therefore, developers must manually analyse stored procedures and business logic, making educated guesses about dependencies and potential risks.
With decades of accumulated complexity, we needed a smarter, more scalable approach to understanding and modernising our SQL estate. Given the pace of technological evolution and our continuous system enhancements, it became essential to find a way to streamline the modernisation process while minimising risk.
Finding the solution fit perfectly within the Platform Innovation team’s remit. We are dedicated to exploring, developing and deploying cutting edge technologies that enhance bet365’s operational efficiency and technical capabilities.
Image
Description
Bet365 has its headquarters in Stoke-on-Trent, as well as satellite offices around the world
GenAI’s ability to rapidly ingest complex information and summarise what it’s looking at positioned it as a powerful tool for overcoming the complexity of code modernisation. The idea was to put an AI in front of our codebase and get it to tell us what it does, what it’s connected to and the potential impact of making changes to it.
However, there is a problem. While AI is very fast, it’s not always effective. Yes, it can do things quickly, but it doesn’t always do them well. For example, a recent BBC report highlighted how often AI gets facts wrong when asked to summarise something as simple as a news story. In theory, Gen AI could be useful in helping us to understand our legacy code, but in practice, the likelihood of it making errors was enormous.
This shaped our challenge. To be successful we needed to give the AI context. In essence, we needed a map of how we’ve developed our code since day one, and why we do it in the way we do. But setting out all the context and nuance needed is almost impossible for a human. Even if we could write out the prompt, there isn’t a window large enough to provide all the context needed.
The solution: Delivering GraphRAG
The breakthrough came when we combined two key techniques: metadata tagging and Graph-based Retrieval-Augmented Generation (GraphRAG).
GraphRAG helps LLMs navigate complex relationships within a dataset. On its own, it provides a map of how elements relate. But it doesn’t explain what any of it means. That’s where metadata tagging is immensely valuable. By enriching our codebase with meta information – labels that explain the business function, historical reasoning, and system dependencies – we built a contextual roadmap.
Image
Description
Metadata tagging proved immensely valuable for providing context to gen AI
Using the full breadth of our MS SQL database estate, which spans hundreds of databases, we extracted every stored procedure, function and join to create a living map of the system. The result was a richly contextualised dataset, surfaced through a chatbot interface that allowed us to query the system using natural language.
To build this capability, we parsed every database object into an abstract syntax tree and used Microsoft’s ScriptDOM to extract relevant facts. These were then compiled into a knowledge graph (KG). We enriched this graph with natural language descriptions to make the data more interpretable.
The result was a detailed representation of tables, functions, stored procedures, views, variables and joins, all mapped with their relationships and usage patterns. Finally, we added runtime statistics, including execution counts, CPU time, and physical and logical read metrics.
A true partner
This implementation transformed AI into a true partner. Instead of feeding it pages of documentation or crafting complex prompts, which would need to provide bespoke context for each inquiry, we could ask simple, natural language questions like, “What is this procedure connected to?” or “What impact will this change have?”, and the AI would deliver answers grounded in our environment and experience. It reveals the impact, highlights the risk and even suggests the fix.
AI no longer replaces human judgement. It informs it.
We’ve also gone one step further and built a tool developers can use to create a visual representation of the AI generated summary in real-time. The tool renders a 3D model of the code with all its procedures and interdependencies. By refining how AI understands and interacts with our data, we’ve transformed prompt engineering from a bottleneck into a competitive advantage.
Image
Description
Rather than replacing human judgement, AI works with them
The results have been impressive. Our AI can now parse and understand our codebase, providing insights that previously required extensive manual effort. Developers can assess the potential impact of change with much greater accuracy, reducing the likelihood of system failures. What previously took weeks of manual investigation can now be completed in hours, improving both speed and accuracy.
One key application is our data warehouse migration project. Our Data Engineering team is leveraging the visualisation tool to support the migration of our SQL database to the cloud. By building a visual representation of the database, they can see its current design. They can then figure out how to redesign it for the modern cloud environment so that we can leverage all its benefits.
Next steps and the future of code modernisation
The next step is embedding this intelligence into our QA and design planning. If AI can analyse code before it’s deployed – highlighting issues, surfacing dependencies, flagging conflicts – it becomes a form of continuous assurance.
We’re also expanding our approach beyond SQL. The same GraphRAG and tagging principles can be applied to other languages and frameworks, unlocking a scalable, cross-platform modernisation engine.
We’ve proven that with the right blend of human ingenuity and machine intelligence we can transform code modernisation. We’re no longer trying to document the past just to keep up with the future. We’re designing systems that are self-aware, self-explaining, and ultimately, self-improving. For our Platform Innovation team, that’s the real breakthrough. Not just making things faster, but making them smarter.