A Stock Trading System
Can we replace a legacy mainframe-based stock trading system with personal computers running J2EE? Advantages include cheap, easier maintenance, more server varieties and maybe, faster transactions.
I assume here that most of us have some understanding of what J2EE is. It is the enterprise platform of JAVA for building applications in various domains. I may add another blog on J2EE later on for further understanding. Let me give a brief overview of the stock trading system though my knowledge about it is very limited. It is a complex system and I can only cover the core and basic components.
There are two main data categories in a stock trading system - data about the securities and the brokers. Brokers have access to buy, sell trade orders of different securities. The security data is stored in a Security Master and brokers' data is stored in a Trade Master. When a broker places a trade order for a particular security, the system should validate the order and then do a order matching with the information stored in the Security Master. If a match does occur, and without violating the ACID (Atomic Consistent Isolated Durable) properties, the correct number of shares are bought or sold by that broker and the data is updated in those tables in the database. This is one of the basic transactions taking place in a stock trading system. Now imagine thousands of such operations occur every minute. We need a system which should handle such traffic without causing much delays.
The project involves a 3-tier architecture. A front-end, middleware and a backend. Backend consists of a database and front-end involves Swing applications or JSP based interface for the brokers to place orders. Middleware would be where the business logic would lie. One of the core components of the business logic is order matching. It needs to be done really quick otherwise it can become the bottleneck. After working for a couple of months, I came out with a dynamic data structure using core JAVA which can handle order matching. Our goal was to handle 100 requests per second and the data structure was giving me that performance. In fact, the performance of this data structure was tested and proved to be better than the one that was created using JAVA's own TreeMap data structure.
Entity Beans are needed for maintaining the Security Master and Trade Master. They need to be mapped with the respective tables in the database. Session beans can handle the authentication of the user, validation of requests, buy and sell trade order processing and broadcast data generation. Broadcasting the data is like a ticker that shows the latest status of each security on every frontend. The front-end module posts a request to servlets/JSP pages, which in turn call the Session Beans. A queueing mechanism like MQ Series can be used to create message queues to constantly sent data to the Broadcast server, which in turn takes care of the broadcast of the trading details.
So, what can the stock exchange achieve from this system? An increase in growth of users, handle heavy trading activity with less delays, deliver responses to users within a few seconds and a huge reduction of infrastructure costs.