Search Sreeni's Insights

Filter by content type
technical March 11, 2020 9 min read

Lessons Learned: Revamping Web Forms into Web API and AngularJS - Part 1

Lessons from moving Web Forms sites to an ASP.NET Web API and AngularJS SPA, including maintainability, performance, SEO and a reversed WCF decision.

Share:

Lessons Learned: Revamping Web Forms into Web API and AngularJS - Part 1

Every successful system eventually becomes a victim of its own success. It grows with the business, new features are added year after year, new sites are built on top of the same code, and one day the team realizes that every change is risky and every page is slow. That is what happened to one of our oldest platforms, a set of ASP.NET Web Forms sites serving mutual fund information to investors across different regions.

In 2015, we decided to revamp the main site into an ASP.NET Web API back-end and an AngularJS Single Page Application (SPA). In this article series, I share our first-hand experience of that journey, what we did, what went well, what went wrong and what I learned as the architect and mentor who drove it. This first part covers the context, the challenges that forced the revamp and the technical decisions we made, including one we had to reverse in the middle of the project.

TL;DR Summary

  • Our Web Forms platform served multiple regional mutual fund marketing sites from the same code base and the same base libraries.
  • Over the years, three problems grew together, maintainability, performance and the monolithic structure, where a change for one site impacted the other sites.
  • The slow searching and rendering of the fund data started to hurt the SEO, which is critical for a marketing site.
  • We decided to revamp the main site into ASP.NET Web API and AngularJS, with a clean separation between the front-end and the back-end.
  • We started with WCF for the services and switched to Web API in the middle of the project. Choosing WCF was a mistake we made by looking at our own experience, not at where the market was going.
  • Technology was only half of the change. The other half was the people, which we will cover in the next part.

The Context

The platform was a set of regional marketing sites for mutual funds. Each site showed the funds available in that region, with their factsheets, prices and performance, and the related marketing content. Investors, advisers and distributors used these sites to search for funds, compare them and download the documents.

Since these were marketing sites, digital marketing was one of the primary things, and it was already implemented solidly in the existing system. The pages were rendered on the server, the search engines could crawl them easily, the SEO was in good shape, and the ads and the analytics worked as expected.

All the regional sites were built from the same code base. They shared the same base libraries, the same data access, the same page templates and the same business logic, with some regional customization on top of it. When it was built, this was a smart decision. One code base meant one team could build a new regional site quickly.

The Crux Of The Problem

As days went by, the same decisions that made the platform successful started to hurt us. Let us discuss the main challenges.

Maintainability

Years of features, customizations and quick fixes made the code base hard to understand and harder to change. Web Forms mixed the presentation and the logic in the code-behind files, the view state and the server controls, so the business logic was spread across pages and user controls. A simple change needed a developer who knew the history of that page, and every change needed a lot of manual testing.

The monolith, one change impacts another site

Since all the regional sites shared the same code base and base libraries, a change made for one site could break another site. A fix in a shared library for one region changed the behavior of a page in a different region. So, every release needed testing across all the sites, the releases became slower and bigger, and the teams became afraid of touching the shared code.

Performance

The fund data grew every year, more funds, more share classes, more prices and longer performance history. Searching the funds and rendering the factsheets, prices and performance pages became slower and slower. The pages were heavy, with large view states and full page postbacks for simple interactions like filtering a list or changing a period on a chart.

SEO

For a marketing site, the performance problem is also a marketing problem. Slow pages hurt the user experience, and the search engines take the page speed into account. Slow searching and rendering caused a lot of SEO issues, and the SEO was exactly the area where the sites used to be strong.

In simple terms, we had a platform that was hard to change, slow to use, and risky to release, and the business was feeling it.

The Decision

Considering all these challenges, we decided to revamp the main site in 2015. We didn’t want to fix the same problems inside Web Forms again. The goals were clear,

  • Separate the front-end from the back-end, so the presentation and the business logic can change and be tested independently.
  • Expose the fund data through services, so the same data can serve the main site, the other regional sites in the future, and other channels.
  • Improve the performance of searching and rendering the fund data.
  • Break the dependency between the sites, so a change for one site doesn’t impact another.
  • Make the code testable, with unit tests as part of the development, not as an afterthought.

We chose a Single Page Application with AngularJS for the front-end and services on .NET for the back-end. At that time, AngularJS was the most popular and mature framework for SPAs, it had a big community, good documentation and a clear structure with modules, controllers, services and dependency injection, which looked familiar to .NET developers. The SPA promised fast interactions without full page reloads, which looked like the perfect answer to our performance problem.

WCF First, Then Web API

For the services, we initially chose Windows Communication Foundation (WCF). The decision was based on the technical capabilities, the team’s experience and the extensibility,

  • WCF was very capable, it supported multiple protocols and bindings, and it could also expose REST endpoints.
  • The team already had experience with WCF services in other projects.
  • It was highly extensible, with behaviors, inspectors and custom bindings for almost anything.

In the middle of the project, we changed to ASP.NET Web API. The SPA needed simple, lightweight HTTP and JSON services, and WCF made it harder than it should be. The REST support in WCF was an add-on to a framework designed for SOAP, the configuration was heavy, and every simple thing needed more ceremony than in Web API. Web API was designed for exactly what we needed, HTTP services with JSON, routing, content negotiation and a simple programming model, and it was clearly where Microsoft and the community were going.

What we didn’t know at that time was how soon WCF would fade away. Today, ASP.NET Core doesn’t support hosting WCF services at all, and the new projects in the .NET world are built with Web API. If we had stayed with WCF, we would have built a new system on a technology that was already on its way out.

The switch in the middle of the project cost us time and rework, and it also confused the team, who had just started to learn the first choice. We will discuss this mistake in detail in the last part of this series.

The Architecture

The new architecture was simple on paper,

  • AngularJS SPA - It runs in the browser, renders the pages and calls the APIs. All the presentation logic lives here.
  • ASP.NET Web API - It exposes the fund search, factsheets, prices and performance as RESTful services, returning JSON.
  • Business and data layers - They contain the business logic and the data access, separated from the API and fully unit tested.
  • Shared base framework - A scaffolding I built for both the front-end and the back-end, with the project structure, the common services, the error handling, the logging and the testing setup, so the team could focus on the features.

[confirm: add a diagram of the architecture if you have one, or let me know and I can create it]

Self-Reflection

Looking back, the reasons for the revamp were right. The platform really had the maintainability, performance and monolith problems, and doing nothing was not an option. But I made the decision mostly through the technical lens. I was looking at the performance, the clean separation and the testability, and I assumed the rest would follow.

It didn’t. The technology was new, the process was new and the way of working was new, all at the same time, and for a team that had worked with Web Forms for years, it was too much at once. And the SPA that solved our performance problem created a new problem in the area where we were strongest, the SEO and the ads.

Wrap up

In this article, we have looked at the context of our Web Forms platform, the maintainability, monolith, performance and SEO challenges that forced the revamp, the decision to move to ASP.NET Web API and AngularJS, and why we switched from WCF to Web API in the middle of the project. I really appreciate that you took the time to read this article. In the next article, I will walk you through the people side of this journey, the developer mindset, the move from waterfall to Scrum, the resistance, and what happened when the decision maker suddenly became the bottleneck.

Related Posts