Code is run on the blockchain through the use of smart contracts. Each smart contract has an address, storage, and code. When a transaction is sent to a contract's address, it's code is run on every node, inside the Ethereum Virtual Machine (EVM), and the contract can send Ether, call other contracts, and write to it's own storage.
Scaling is handled through the use of gas. Every computational step, even sending a regular transaction or creating a contract, requires some amount of gas (which can be negative for operations like deleting stored data). This gas is sent along with the transaction, and is paid to the miner, and if insufficient gas is provided, all state changes are rolled back.
When a transaction is sent, the user specifies the maximum gas that they are willing to spend, and the price (in Ether per gas) that they are willing to pay for it. Miners are then able to choose to process transactions that provide the highest gas price.
Miners also get to choose the block gas limit
The gas limit determines how much computation and storage can be used per block. On each block, the miner gets to set the new gas limit, but may only increase or decrease the limit by 1/1024th of the previous limit.
This means that miners are able to vote to keep the block sizes small enough to process, and the price of computation is flexible, depending on supply and demand.
Other scaling techniques
Off-chain computation:
- By using computation markets, code execution can be done off-chain by default, and only verified on-chain if there is a dispute.
State Channels:
- Similar to payment channels, parties lock some part of the state into a contract that requires signatures from all parties to edit. Parties transact amongst themselves and only submit the updated state if there is a dispute.
More theoreticall stuff: