It is a form of N-Tier Architecture. Initially, most sites wills start out as a 2 Tier architecture, having a webserver and a database. The webserver will serve up the pages that the user sees, while the database is accessed by those dynamic pages.
When an architecture is separated into multiple tiers, usually, you will have a Web Application at the front, with some kind of application server which the web application will call. This application server contains the business logic and makes the application functional. The "face" for the application simply makes things look pretty and formats it for display to users.
The application server, or "middleware", is simply a collection of functions that can be called by the web servers. The middleware must be powerful for a site like twitter where most of the activity is in sending messages, and there is not so much activity from people accessing the website.
The interconnect between layers is likely a standard web service technology, but it could be a custom thing, perhaps a REST or some other kind of web service where the web application(Ruby on Rails) can access application data.
In this type of architecture, Rails most certainly has relegated all ORM and data management to the middleware.
Middleware is also a vague term and can consist of many Tiers, hence why they call it N-Tier. I would bet that Twitter has a different part of their middleware devoted to messaging while another part deals with managing accounts, fetching messages, etc.
The idea is to be able to scale upwards by adding hardware, where you can have a cluster of servers serving up web pages, another cluster handling messaging, and then a cluster of database servers that support it all. It's not an exact science, each architecture is different, but generally, this is how it can be thought of.