Get or Create a Node in a Custom Module
Create or use an existing content type for your nodes.
Add a field (field_ext_id) on the content type to track your external content id.
When building your page, use EntityFieldQuery (note that it may have performance implications on very large sites) to look for a node with field_ext_id = your id.
If no node found, create one:

$node = new stdClass;
$node-&gt;type = 'your_content_type';
$node-&gt;status = 1;
$node-&gt;uid = 1;
$node-&gt;title = 'my node';
$node-&gt;created = REQUEST_TIME;
$node-&gt;updated = REQUEST_TIME;

// set your other field values (including field_ext_id), as necessary

node_save($node);

// your new node's id is now available as $node-&gt;nid


For working with fields, have a look at Rendering Drupal 7 Fields The Right Way and Entity Metadata Wrapper.